# APPENDIX D, CODE

# Install and load packages if not already done
packages <- c("plyr", "ggplot2", "zoo", "scales", "stringr", "dplyr", "tidyverse", "text2vec", 
              "lubridate", "data.table", "quanteda", "quanteda.textstats", "magrittr", 
              "fixest", "modelsummary", "marginaleffects", "texreg", "gridExtra")
install_and_load <- function(package) {
  if (!require(package, character.only = TRUE)) {
    install.packages(package, dependencies = TRUE)
    library(package, character.only = TRUE)
  }
}
invisible(lapply(packages, install_and_load))

# Load data
setwd("FOLDER PATH")
load('df_ft_all_final.rda')

# Removing speaker
df_ft_all <- subset(df_ft_all, party != 1)

# COUNTING SIGNALING

# Count, co-optation
df_ft_all$arbejdsløshedskasse <- str_count(df_ft_all$tokens_edit, "arbejdsløshedskasse")
df_ft_all$arbejdsløshedsunderstøttelse <- str_count(df_ft_all$tokens_edit, "arbejdsløshedsunderstøttelse")
df_ft_all$arbejdsløshedslov <- str_count(df_ft_all$tokens_edit, "arbejdsløshedslov")
df_ft_all$arbejdsløshedsstøtte <- df_ft_all$arbejdsløshedskasse + df_ft_all$arbejdsløshedsunderstøttelse + df_ft_all$arbejdsløshedslov
df_ft_all$arbejdsdag <- str_count(df_ft_all$tokens_edit, "arbejdsdag")
df_ft_all$dyrtid <- str_count(df_ft_all$tokens_edit, "dyrtidsforanstaltning") + str_count(df_ft_all$tokens_edit, "dyrtidstillæg")
df_ft_all$aldersrente <- str_count(df_ft_all$tokens_edit, "aldersrente")
df_ft_all$merindkomstskat <- str_count(df_ft_all$tokens_edit, "merindkomstskat") + str_count(df_ft_all$tokens_edit, "tillægsskat") + str_count(df_ft_all$tokens_edit, "ekstraordinære indkomstskat") + str_count(df_ft_all$tokens_edit, "ekstraordinær indkomstskat") + str_count(df_ft_all$tokens_edit, "formueskat")

# Count, revolutionary terms (revolutionary opportunism)
df_ft_all$revolution <- str_count(df_ft_all$tokens_edit, "revolution")
df_ft_all$socialisme <- str_count(df_ft_all$tokens_edit, "socialis")
df_ft_all$bolschev <- str_count(df_ft_all$tokens_edit, "bolschev")
df_ft_all$kommunis <- str_count(df_ft_all$tokens_edit, "kommunis")
df_ft_all$anarkis <- str_count(df_ft_all$tokens_edit, "anarkist") + str_count(df_ft_all$tokens_edit, "anarkism")
df_ft_all$syndikalis <- str_count(df_ft_all$tokens_edit, "syndikalis")
df_ft_all$socrevall <- df_ft_all$socialisme + df_ft_all$revolution + df_ft_all$bolschev + df_ft_all$kommunis + df_ft_all$anarkis + df_ft_all$syndikalis

# Count, repression
df_ft_all$repress <- 
  str_count(df_ft_all$tokens_edit, "deport") + str_count(df_ft_all$tokens_edit, " nedskyde ") +
  str_count(df_ft_all$tokens_edit, " aabne ild") + 
  str_count(df_ft_all$tokens_edit, " skal fængsel ") +
  str_count(df_ft_all$tokens_edit, " komme fængsel ") +
  str_count(df_ft_all$tokens_edit, " sættes fængsel ") +
  str_count(df_ft_all$tokens_edit, "fængsles") +
  str_count(df_ft_all$tokens_edit, "henret") + str_count(df_ft_all$tokens_edit, "straffe ") +
  str_count(df_ft_all$tokens_edit, "overvaag") + str_count(df_ft_all$tokens_edit, "arrestere") +
  str_count(df_ft_all$tokens_edit, "straffelov")

## Making IV 
df_ft_all$y17_19 <- as.numeric(format(df_ft_all$date, '%Y-%m-%d') %between% c('1917-03-08', '1919-08-11'))
df_ft_all_y17_19 <- subset(df_ft_all, format(as.Date(date),"%Y-%m-%d")<'1919-08-12')

## Year cluster
breaks <- seq(as.Date('1910-01-01'), as.Date('1917-03-07'), length.out = 6)
df_ft_all_y17_19 <- df_ft_all_y17_19 %>%
  mutate(year_cluster = cut(date, breaks, labels = FALSE))
df_ft_all_y17_19$year_cluster[df_ft_all_y17_19$date >= as.Date('1917-03-08') &
                                df_ft_all_y17_19$date <= as.Date('1919-08-11')] <- 'Revolution'
df_ft_all_y17_19$year_cluster <- factor(df_ft_all_y17_19$year_cluster)
df_ft_all_y17_19$year_cluster <- relevel(df_ft_all_y17_19$year_cluster, ref = "5")

# D1

## Regressions

# Unemployment compensation
glmarbejdsløshedsimple17_19 <- feglm(
  arbejdsløshedsstøtte~y17_19, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

glmarbejdsløshedsimple17_19_inf <- feglm(
  arbejdsløshedsstøtte~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Working day

glmarbejdsdag17_19 <- feglm(
  arbejdsdag~y17_19, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

glmarbejdsdag17_19_inf <- feglm(
  arbejdsdag~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Price increase compensation

glmdyrtid17_19 <- feglm(
  dyrtid~y17_19, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

glmdyrtid17_19_inf <- feglm(
  dyrtid~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Additional taxation
glmmerindkomstskat17_19 <- feglm(
  merindkomstskat~y17_19, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

glmmerindkomstskat17_19_inf <- feglm(
  merindkomstskat~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Regressions, policies, parties
# Unemployment support
glmarbejdsløshedssimple17_19_s_inf <- feglm(
  arbejdsløshedsstøtte ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmarbejdsløshedssimple17_19_k_inf <- feglm(
  arbejdsløshedsstøtte ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmarbejdsløshedssimple17_19_v_inf <- feglm(
  arbejdsløshedsstøtte ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)),
  family = quasipoisson(),
  se = "hetero")

glmarbejdsløshedssimple17_19_r_inf <- feglm(
  arbejdsløshedsstøtte ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

# Working day
glmarbejdsdagsimple17_19_s_inf <- feglm(
  arbejdsdag ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmarbejdsdagsimple17_19_k_inf <- feglm(
  arbejdsdag ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmarbejdsdagsimple17_19_v_inf <- feglm(
  arbejdsdag ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)),
  family = quasipoisson(),
  se = "hetero")

glmarbejdsdagsimple17_19_r_inf <- feglm(
  arbejdsdag ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

# Price increase compensation
glmdyrtidsimple17_19_s_inf <- feglm(
  dyrtid ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmdyrtidsimple17_19_k_inf <- feglm(
  dyrtid ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmdyrtidsimple17_19_v_inf <- feglm(
  dyrtid ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)), 
  family = quasipoisson(),
  se = "hetero")

glmdyrtidsimple17_19_r_inf <- feglm(
  dyrtid ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

# Additional tax
glmmerindkomstskatsimple17_19_s_inf <- feglm(
  merindkomstskat ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmmerindkomstskatsimple17_19_k_inf <- feglm(
  merindkomstskat ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmmerindkomstskatsimple17_19_v_inf <- feglm(
  merindkomstskat ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)), 
  family = quasipoisson(),
  se = "hetero")

glmmerindkomstskatsimple17_19_r_inf <- feglm(
  merindkomstskat ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

# Revolutionary terms

glmsocrevall17_19 <- feglm(
  socrevall~y17_19, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

glmsocrevall17_19_inf <- feglm(
  socrevall~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Regressions, revolutionary terms, parties

glmsocrevall17_19_sinf <- feglm(
  socrevall ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmsocrevall17_19_kinf <- feglm(
  socrevall ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmsocrevall17_19_vinf <- feglm(
  socrevall ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)),
  family = quasipoisson(),
  se = "hetero")

glmsocrevall17_19_rinf <- feglm(
  socrevall ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

# Repression

glmrepress17_19 <- feglm(
  repress~y17_19, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

glmrepress17_19_inf <- feglm(
  repress~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Repression, parties

glmrepress17_19_sinf <- feglm(
  repress ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmrepress17_19_kinf <- feglm(
  repress ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmrepress17_19_vinf <- feglm(
  repress ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)),
  family = quasipoisson(),
  se = "hetero")

glmrepress17_19_rinf <- feglm(
  repress ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

# Revolutionary terms and repression or co-optation, aggregate

df_ft_all$socrevall_coopt <- ifelse(df_ft_all$socrevall > 0 & (df_ft_all$arbejdsløshedsstøtte > 0 | df_ft_all$dyrtid > 0 | df_ft_all$arbejdsdag > 0 | df_ft_all$merindkomstskat > 0), 1, 0)
df_ft_all$socrevall_repress <- ifelse(df_ft_all$socrevall > 0 & df_ft_all$repress > 0, 1, 0)
df_ft_all$y17_19 <- as.numeric(format(df_ft_all$date, '%Y-%m-%d') %between% c('1917-03-08', '1919-08-11'))
df_ft_all_y17_19 <- subset(df_ft_all, format(as.Date(date),"%Y-%m-%d")<'1919-08-12')
df_ft_all_y17_19$year <- as.numeric(df_ft_all_y17_19$year)
library(fixest)
library(broom)
library(ggplot2)
library(dplyr)

glmsocrevallcoopt17_19_inf <- feglm(
  socrevall_coopt~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

glmsocrevallrepress17_19_inf <- feglm(
  socrevall_repress~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Revolutionary terms and repression or co-optation, parties

glmsocrevall_repress17_19_sinf <- feglm(
  socrevall_repress ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmsocrevall_repress17_19_kinf <- feglm(
  socrevall_repress ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmsocrevall_repress17_19_vinf <- feglm(
  socrevall_repress ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)),
  family = quasipoisson(),
  se = "hetero")

glmsocrevall_repress17_19_rinf <- feglm(
  socrevall_repress ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

glmsocrevall_coopt17_19_sinf <- feglm(
  socrevall_coopt ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmsocrevall_coopt17_19_kinf <- feglm(
  socrevall_coopt ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmsocrevall_coopt17_19_vinf <- feglm(
  socrevall_coopt ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)),
  family = quasipoisson(),
  se = "hetero")

glmsocrevall_coopt17_19_rinf <- feglm(
  socrevall_coopt ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

# Robustness to MP change

df_ft_all$y17_19 <- as.numeric(format(df_ft_all$date, '%Y-%m-%d') %between% c('1917-03-08', '1919-08-11'))
df_ft_all_y17_19 <- subset(df_ft_all, format(as.Date(date),"%Y-%m-%d")<'1919-08-12')
df_ft_all_y17_19_1910 <- df_ft_all_y17_19 %>%
  filter(!(y17_19 == 1 & `1910_or_before` != 1))
df_ft_all_y17_19_1910_notempmembers <- df_ft_all_y17_19_1910 %>%
  filter(is.na(not_member_election_10_18) )
df_ft_all_y17_19_1910_notempmembers <- df_ft_all_y17_19_1910_notempmembers %>%
  filter(is.na(not_member_14_18) )
df_ft_all_y17_19_1910_notempmembers <- df_ft_all_y17_19_1910_notempmembers %>%
  filter(is.na(not_member_13_18) )
df_ft_all_y17_19_1910_notempmembers <- df_ft_all_y17_19_1910_notempmembers %>%
  filter(is.na(not_member_10_16) )

glmsocrevall17_19_inf_subset <- feglm(
  socrevall~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_1910_notempmembers,
  family = quasipoisson(),
  se = "hetero")

glmarbejdsløshedsstøtte17_19_inf_subset <- feglm(
  arbejdsløshedsstøtte~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_1910_notempmembers,
  family = quasipoisson(),
  se = "hetero")

glmarbejdsdag17_19_inf_subset <- feglm(
  arbejdsdag~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_1910_notempmembers,
  family = quasipoisson(),
  se = "hetero")

glmdyrtid17_19_inf_subset <- feglm(
  dyrtid~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_1910_notempmembers,
  family = quasipoisson(),
  se = "hetero")

glmmerindkomstskat17_19_inf_subset <- feglm(
  merindkomstskat~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_1910_notempmembers,
  family = quasipoisson(),
  se = "hetero")

glmrepress17_19_inf_subset <- feglm(
  repress~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_1910_notempmembers,
  family = quasipoisson(),
  se = "hetero")

# Tables, D1, aggregate

texreg(
  list(glmarbejdsløshedsimple17_19, glmarbejdsløshedsimple17_19_inf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("No controls", "Controls"),
  caption = "Unemployment support",
  stars = c(0.05, 0.01, 0.001),   include.loglik = FALSE,   include.pseudors = FALSE, caption.above = TRUE,  
)

texreg(
  list(glmarbejdsdag17_19, glmarbejdsdag17_19_inf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("No controls", "Controls"),
  caption = "Working day",
  stars = c(0.05, 0.01, 0.001),   include.loglik = FALSE,   include.pseudors = FALSE, caption.above = TRUE,  
)

texreg(
  list(glmdyrtid17_19, glmdyrtid17_19_inf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("No controls", "Controls"),
  caption = "Price increase compensation",
  stars = c(0.05, 0.01, 0.001),   include.loglik = FALSE,   include.pseudors = FALSE, caption.above = TRUE,  
)

texreg(
  list(glmmerindkomstskat17_19, glmmerindkomstskat17_19_inf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("No controls", "Controls"),
  caption = "Additional taxation",
  stars = c(0.05, 0.01, 0.001),   include.loglik = FALSE,   include.pseudors = FALSE, caption.above = TRUE,  
)


texreg(
  list(glmrepress17_19, glmrepress17_19_inf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("No controls", "Controls"),
  caption = "Repression",
  stars = c(0.05, 0.01, 0.001), include.loglik = FALSE,   include.pseudors = FALSE, caption.above = TRUE,  
)

texreg(
  list(glmsocrevall17_19, glmsocrevall17_19_inf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("No controls", "Controls"),
  caption = "Revolutionary terms",
  stars = c(0.05, 0.01, 0.001),   include.loglik = FALSE,   include.pseudors = FALSE, caption.above = TRUE,  
)

texreg(
  list(glmsocrevallcoopt17_19_inf, glmsocrevallrepress17_19_inf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Revolutionary terms and co-optation", "Revolutionary terms and repression"),
  caption = "Revolutionary terms and co-optation or repression",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)


# Tables, D1, party level

texreg(
  list(glmarbejdsløshedssimple17_19_s_inf, glmarbejdsløshedssimple17_19_k_inf, glmarbejdsløshedssimple17_19_v_inf, glmarbejdsløshedssimple17_19_r_inf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Unemployment support, parties",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmarbejdsdagsimple17_19_s_inf, glmarbejdsdagsimple17_19_k_inf, glmarbejdsdagsimple17_19_v_inf, glmarbejdsdagsimple17_19_r_inf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Working day, parties",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmdyrtidsimple17_19_s_inf, glmdyrtidsimple17_19_k_inf, glmdyrtidsimple17_19_v_inf, glmdyrtidsimple17_19_r_inf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Price increase compensation, parties",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmmerindkomstskatsimple17_19_s_inf, glmmerindkomstskatsimple17_19_k_inf, glmmerindkomstskatsimple17_19_v_inf, glmmerindkomstskatsimple17_19_r_inf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Additional taxation, parties",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmrepress17_19_sinf, glmrepress17_19_kinf, glmrepress17_19_vinf, glmrepress17_19_rinf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Repression, parties",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmsocrevall17_19_sinf, glmsocrevall17_19_kinf, glmsocrevall17_19_vinf, glmsocrevall17_19_rinf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Revolutionary terms, parties",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)


texreg(
  list(glmsocrevall_repress17_19_sinf, glmsocrevall_repress17_19_kinf, glmsocrevall_repress17_19_vinf, glmsocrevall_repress17_19_rinf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Revolutionary terms and repression, parties",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmsocrevall_coopt17_19_sinf, glmsocrevall_coopt17_19_kinf, glmsocrevall_coopt17_19_vinf, glmsocrevall_coopt17_19_rinf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Revolutionary terms and co-optation, parties",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

# Tables, robustness to MP change
texreg(
  list(glmarbejdsløshedsstøtte17_19_inf_subset, glmarbejdsdag17_19_inf_subset, glmdyrtid17_19_inf_subset, glmmerindkomstskat17_19_inf_subset),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Unempl. benefits", "Working day", "Price inc. comp.", "Add. taxation"),
  caption = "Signaling on policies, robustness to MP change",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmsocrevall17_19_inf_subset, glmrepress17_19_inf_subset),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Revolutionary terms", "Repression"),
  caption = "Signaling on revolutionary terms and repression, robustness to MP change",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

# Percentage changes in signaling

exp(coef(glmarbejdsløshedsimple17_19_inf)["y17_19"])
exp(coef(glmarbejdsdag17_19_inf)["y17_19"])
exp(coef(glmdyrtid17_19_inf)["y17_19"])
exp(coef(glmmerindkomstskat17_19_inf)["y17_19"])
exp(coef(glmrepress17_19_inf)["y17_19"])
exp(coef(glmsocrevall17_19_inf)["y17_19"])

# D2. Placebo tests

## Making placebo IV

df_ft_all$y17_19_placebo <- as.numeric(format(df_ft_all$date, "%Y-%m-%d") %between% c('1914-07-28', '1917-03-07'))
df_ft_all_y17_19_placebo <- subset(df_ft_all, format(as.Date(date),"%Y-%m-%d")<'1917-03-08')

df_ft_all$y17_19_placebo_comint2 <- as.numeric(format(df_ft_all$date, "%Y-%m-%d") %between% c('1917-03-08', '1920-03-07'))
df_ft_all_y17_19_placebo_comint2 <- subset(df_ft_all, format(as.Date(date),"%Y-%m-%d")<'1920-03-08')

## Aggregate, placebo 1914

glmarbejdsløshedsssimple17_19_inf_placebo <- feglm(
  arbejdsløshedsstøtte~y17_19_placebo  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_placebo,
  family = quasipoisson(),
  se = "hetero")

glmarbejdsdag17_19_inf_placebo <- feglm(
  arbejdsdag~y17_19_placebo  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_placebo,
  family = quasipoisson(),
  se = "hetero")

glmdyrtid17_19_inf_placebo <- feglm(
  dyrtid~y17_19_placebo  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_placebo,
  family = quasipoisson(),
  se = "hetero")

glmmerindkomstskat17_19_inf_placebo <- feglm(
  merindkomstskat~y17_19_placebo  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_placebo,
  family = quasipoisson(),
  se = "hetero")

glmsocrevall17_19_inf_placebo <- feglm(
  socrevall~y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_placebo,
  family = quasipoisson(),
  se = "hetero")

glmrepress17_19_inf_placebo <- feglm(
  repress~y17_19_placebo  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_placebo,
  family = quasipoisson(),
  se = "hetero")

df_ft_all$socrevall_coopt <- ifelse(df_ft_all$socrevall > 0 & (df_ft_all$arbejdsløshedsstøtte > 0 | df_ft_all$dyrtid > 0 | df_ft_all$arbejdsdag > 0 | df_ft_all$merindkomstskat > 0), 1, 0)
df_ft_all$socrevall_repress <- ifelse(df_ft_all$socrevall > 0 & df_ft_all$repress > 0, 1, 0)

glmsocrevallcoopt17_19_inf_placebo <- feglm(
  socrevall_coopt~y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_placebo,
  family = quasipoisson(),
  se = "hetero")

glmsocrevallrepress17_19_inf_placebo <- feglm(
  socrevall_repress~y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_placebo,
  family = quasipoisson(),
  se = "hetero")

## Parties 

#Arbejdsløshedsstøtte
glmarbejdsløshedssimple17_19_s_inf_placebo <- feglm(
  arbejdsløshedsstøtte ~ y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmarbejdsløshedssimple17_19_k_inf_placebo <- feglm(
  arbejdsløshedsstøtte ~ y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmarbejdsløshedssimple17_19_v_inf_placebo <- feglm(
  arbejdsløshedsstøtte ~ y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo, party %in% c(4, 13, 14, 15, 103)),
  family = quasipoisson(),
  se = "hetero")

glmarbejdsløshedssimple17_19_r_inf_placebo <- feglm(
  arbejdsløshedsstøtte ~ y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

#Arbejdsdag
glmarbejdsdagsimple17_19_s_inf_placebo <- feglm(
  arbejdsdag ~ y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmarbejdsdagsimple17_19_k_inf_placebo <- feglm(
  arbejdsdag ~ y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmarbejdsdagsimple17_19_v_inf_placebo <- feglm(
  arbejdsdag ~ y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo, party %in% c(4, 13, 14, 15, 103)),
  family = quasipoisson(),
  se = "hetero")

glmarbejdsdagsimple17_19_r_inf_placebo <- feglm(
  arbejdsdag ~ y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

#Dyrtid

glmdyrtidsimple17_19_s_inf_placebo <- feglm(
  dyrtid ~ y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmdyrtidsimple17_19_k_inf_placebo <- feglm(
  dyrtid ~ y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmdyrtidsimple17_19_v_inf_placebo <- feglm(
  dyrtid ~ y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo, party %in% c(4, 13, 14, 15, 103)), 
  family = quasipoisson(),
  se = "hetero")

glmdyrtidsimple17_19_r_inf_placebo <- feglm(
  dyrtid ~ y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

#Merindkomstskat
glmmerindkomstskatsimple17_19_s_inf_placebo <- feglm(
  merindkomstskat ~ y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmmerindkomstskatsimple17_19_k_inf_placebo <- feglm(
  merindkomstskat ~ y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmmerindkomstskatsimple17_19_v_inf_placebo <- feglm(
  merindkomstskat ~ y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo, party %in% c(4, 13, 14, 15, 103)), 
  family = quasipoisson(),
  se = "hetero")

glmmerindkomstskatsimple17_19_r_inf_placebo <- feglm(
  merindkomstskat ~ y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

# Revolutionary terms, parties, placebo

glmsocrevall17_19_sinf_placebo <- feglm(
  socrevall ~ y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmsocrevall17_19_kinf_placebo <- feglm(
  socrevall ~ y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmsocrevall17_19_vinf_placebo <- feglm(
  socrevall ~ y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo, party %in% c(4, 13, 14, 15, 103)),
  family = quasipoisson(),
  se = "hetero")

glmsocrevall17_19_rinf_placebo <- feglm(
  socrevall ~ y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

# Repression, parties, placebo

glmrepress17_19_sinf_placebo <- feglm(
  repress ~ y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmrepress17_19_kinf_placebo <- feglm(
  repress ~ y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmrepress17_19_vinf_placebo <- feglm(
  repress ~ y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo, party %in% c(4, 13, 14, 15, 103)),
  family = quasipoisson(),
  se = "hetero")

glmrepress17_19_rinf_placebo <- feglm(
  repress ~ y17_19_placebo + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

## Aggregate, alt. ending 1920

glmarbejdsløshedsssimple17_19_inf_placebo_comint2 <- feglm(
  arbejdsløshedsstøtte~y17_19_placebo_comint2  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_placebo_comint2,
  family = quasipoisson(),
  se = "hetero")

glmarbejdsdag17_19_inf_placebo_comint2 <- feglm(
  arbejdsdag~y17_19_placebo_comint2  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_placebo_comint2,
  family = quasipoisson(),
  se = "hetero")

glmdyrtid17_19_inf_placebo_comint2 <- feglm(
  dyrtid~y17_19_placebo_comint2  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_placebo_comint2,
  family = quasipoisson(),
  se = "hetero")

glmmerindkomstskat17_19_inf_placebo_comint2 <- feglm(
  merindkomstskat~y17_19_placebo_comint2  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_placebo_comint2,
  family = quasipoisson(),
  se = "hetero")

glmsocrevall17_19_inf_placebo_comint2 <- feglm(
  socrevall~y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_placebo_comint2,
  family = quasipoisson(),
  se = "hetero")

glmrepress17_19_inf_placebo_comint2 <- feglm(
  repress~y17_19_placebo_comint2  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_placebo_comint2,
  family = quasipoisson(),
  se = "hetero")

df_ft_all$socrevall_coopt <- ifelse(df_ft_all$socrevall > 0 & (df_ft_all$arbejdsløshedsstøtte > 0 | df_ft_all$dyrtid > 0 | df_ft_all$arbejdsdag > 0 | df_ft_all$merindkomstskat > 0), 1, 0)
df_ft_all$socrevall_repress <- ifelse(df_ft_all$socrevall > 0 & df_ft_all$repress > 0, 1, 0)

glmsocrevallcoopt17_19_inf_placebo_comint2 <- feglm(
  socrevall_coopt~y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_placebo_comint2,
  family = quasipoisson(),
  se = "hetero")

glmsocrevallrepress17_19_inf_placebo_comint2 <- feglm(
  socrevall_repress~y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_placebo_comint2,
  family = quasipoisson(),
  se = "hetero")

## Parties, alt. ending 1920

#Arbejdsløshedsstøtte
glmarbejdsløshedssimple17_19_s_inf_placebo_comint2 <- feglm(
  arbejdsløshedsstøtte ~ y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo_comint2, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmarbejdsløshedssimple17_19_k_inf_placebo_comint2 <- feglm(
  arbejdsløshedsstøtte ~ y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo_comint2, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmarbejdsløshedssimple17_19_v_inf_placebo_comint2 <- feglm(
  arbejdsløshedsstøtte ~ y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo_comint2, party %in% c(4, 13, 14, 15, 103)),
  family = quasipoisson(),
  se = "hetero")

glmarbejdsløshedssimple17_19_r_inf_placebo_comint2 <- feglm(
  arbejdsløshedsstøtte ~ y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo_comint2, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

#Arbejdsdag
glmarbejdsdagsimple17_19_s_inf_placebo_comint2 <- feglm(
  arbejdsdag ~ y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo_comint2, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmarbejdsdagsimple17_19_k_inf_placebo_comint2 <- feglm(
  arbejdsdag ~ y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo_comint2, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmarbejdsdagsimple17_19_v_inf_placebo_comint2 <- feglm(
  arbejdsdag ~ y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo_comint2, party %in% c(4, 13, 14, 15, 103)),
  family = quasipoisson(),
  se = "hetero")

glmarbejdsdagsimple17_19_r_inf_placebo_comint2 <- feglm(
  arbejdsdag ~ y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo_comint2, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

#Dyrtid

glmdyrtidsimple17_19_s_inf_placebo_comint2 <- feglm(
  dyrtid ~ y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo_comint2, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmdyrtidsimple17_19_k_inf_placebo_comint2 <- feglm(
  dyrtid ~ y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo_comint2, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmdyrtidsimple17_19_v_inf_placebo_comint2 <- feglm(
  dyrtid ~ y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo_comint2, party %in% c(4, 13, 14, 15, 103)), 
  family = quasipoisson(),
  se = "hetero")

glmdyrtidsimple17_19_r_inf_placebo_comint2 <- feglm(
  dyrtid ~ y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo_comint2, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

#Merindkomstskat
glmmerindkomstskatsimple17_19_s_inf_placebo_comint2 <- feglm(
  merindkomstskat ~ y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo_comint2, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmmerindkomstskatsimple17_19_k_inf_placebo_comint2 <- feglm(
  merindkomstskat ~ y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo_comint2, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmmerindkomstskatsimple17_19_v_inf_placebo_comint2 <- feglm(
  merindkomstskat ~ y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo_comint2, party %in% c(4, 13, 14, 15, 103)), 
  family = quasipoisson(),
  se = "hetero")

glmmerindkomstskatsimple17_19_r_inf_placebo_comint2 <- feglm(
  merindkomstskat ~ y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo_comint2, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

# Revolutionary terms, parties, placebo

glmsocrevall17_19_sinf_placebo_comint2 <- feglm(
  socrevall ~ y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo_comint2, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmsocrevall17_19_kinf_placebo_comint2 <- feglm(
  socrevall ~ y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo_comint2, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmsocrevall17_19_vinf_placebo_comint2 <- feglm(
  socrevall ~ y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo_comint2, party %in% c(4, 13, 14, 15, 103)),
  family = quasipoisson(),
  se = "hetero")

glmsocrevall17_19_rinf_placebo_comint2 <- feglm(
  socrevall ~ y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo_comint2, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

# Repression, parties, placebo

glmrepress17_19_sinf_placebo_comint2 <- feglm(
  repress ~ y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo_comint2, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmrepress17_19_kinf_placebo_comint2 <- feglm(
  repress ~ y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo_comint2, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmrepress17_19_vinf_placebo_comint2 <- feglm(
  repress ~ y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo_comint2, party %in% c(4, 13, 14, 15, 103)),
  family = quasipoisson(),
  se = "hetero")

glmrepress17_19_rinf_placebo_comint2 <- feglm(
  repress ~ y17_19_placebo_comint2 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19_placebo_comint2, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

## Tables, placebo aggregate 1914

texreg(
  list(glmarbejdsløshedsssimple17_19_inf_placebo, glmarbejdsdag17_19_inf_placebo, glmdyrtid17_19_inf_placebo, glmmerindkomstskat17_19_inf_placebo),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Unempl. benefits", "Working day", "Price inc. comp.", "Add. tax"),
  caption = "Co-optation, placebo 1914",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmrepress17_19_inf_placebo, glmsocrevall17_19_inf_placebo),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Repression", "Revolutionary terms"),
  caption = "Repression and revolutionary terms, placebo 1914",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmsocrevallcoopt17_19_inf_placebo, glmsocrevallrepress17_19_inf_placebo),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Co-optation", "Repress"),
  caption = "Revolutionary terms and co-optation or repression, placebo 1914",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

# Parties, placebo 1914

texreg(
  list(glmarbejdsløshedssimple17_19_s_inf_placebo, glmarbejdsløshedssimple17_19_k_inf_placebo, glmarbejdsløshedssimple17_19_v_inf_placebo, glmarbejdsløshedssimple17_19_r_inf_placebo),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Unemployment support, parties, placebo 1914",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmarbejdsdagsimple17_19_s_inf_placebo, glmarbejdsdagsimple17_19_k_inf_placebo, glmarbejdsdagsimple17_19_v_inf_placebo, glmarbejdsdagsimple17_19_r_inf_placebo),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Working day, parties, placebo 1914",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmdyrtidsimple17_19_s_inf_placebo, glmdyrtidsimple17_19_k_inf_placebo, glmdyrtidsimple17_19_v_inf_placebo, glmdyrtidsimple17_19_r_inf_placebo),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Price increase compensation, parties, placebo 1914",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmmerindkomstskatsimple17_19_s_inf_placebo, glmmerindkomstskatsimple17_19_k_inf_placebo, glmmerindkomstskatsimple17_19_v_inf_placebo, glmmerindkomstskatsimple17_19_r_inf_placebo),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Additional taxation, parties, placebo 1914",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmrepress17_19_sinf_placebo, glmrepress17_19_kinf_placebo, glmrepress17_19_vinf_placebo, glmrepress17_19_rinf_placebo),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Repression, parties, placebo 1914",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmsocrevall17_19_sinf_placebo, glmsocrevall17_19_kinf_placebo, glmsocrevall17_19_vinf_placebo, glmsocrevall17_19_rinf_placebo),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Revolutionary terms, parties, placebo 1914",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

## Tables, placebo aggregate 1920

texreg(
  list(glmarbejdsløshedsssimple17_19_inf_placebo_comint2, glmarbejdsdag17_19_inf_placebo_comint2, glmdyrtid17_19_inf_placebo_comint2, glmmerindkomstskat17_19_inf_placebo_comint2),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Unempl. benefits", "Working day", "Price inc. comp.", "Add. tax"),
  caption = "Co-optation, alt. ending 1920",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmrepress17_19_inf_placebo_comint2, glmsocrevall17_19_inf_placebo_comint2),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Repression", "Revolutionary terms"),
  caption = "Repression and revolutionary terms, alt. ending 1920",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmsocrevallcoopt17_19_inf_placebo_comint2, glmsocrevallrepress17_19_inf_placebo_comint2),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Co-optation", "Repress"),
  caption = "Revolutionary terms and co-optation or repression, alt. ending 1920",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

# Parties, alt. ending 1920

texreg(
  list(glmarbejdsløshedssimple17_19_s_inf_placebo_comint2, glmarbejdsløshedssimple17_19_k_inf_placebo_comint2, glmarbejdsløshedssimple17_19_v_inf_placebo_comint2, glmarbejdsløshedssimple17_19_r_inf_placebo_comint2),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Unemployment support, parties, alt. ending 1920",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmarbejdsdagsimple17_19_s_inf_placebo_comint2, glmarbejdsdagsimple17_19_k_inf_placebo_comint2, glmarbejdsdagsimple17_19_v_inf_placebo_comint2, glmarbejdsdagsimple17_19_r_inf_placebo_comint2),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Working day, parties, alt. ending 1920",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmdyrtidsimple17_19_s_inf_placebo_comint2, glmdyrtidsimple17_19_k_inf_placebo_comint2, glmdyrtidsimple17_19_v_inf_placebo_comint2, glmdyrtidsimple17_19_r_inf_placebo_comint2),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Price increase compensation, parties, alt. ending 1920",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmmerindkomstskatsimple17_19_s_inf_placebo_comint2, glmmerindkomstskatsimple17_19_k_inf_placebo_comint2, glmmerindkomstskatsimple17_19_v_inf_placebo_comint2, glmmerindkomstskatsimple17_19_r_inf_placebo_comint2),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Additional taxation, parties, alt. ending 1920",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmrepress17_19_sinf_placebo_comint2, glmrepress17_19_kinf_placebo_comint2, glmrepress17_19_vinf_placebo_comint2, glmrepress17_19_rinf_placebo_comint2),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Repression, parties, alt. ending 1920",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmsocrevall17_19_sinf_placebo_comint2, glmsocrevall17_19_kinf_placebo_comint2, glmsocrevall17_19_vinf_placebo_comint2, glmsocrevall17_19_rinf_placebo_comint2),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Revolutionary terms, parties, alt. ending 1920",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)



# D3. World War I as control

## Making WWI dummy
df_ft_all$wwi <- as.numeric(format(df_ft_all$date, '%Y-%m-%d') %between% c('1914-07-28', '1918-11-11'))

## Making IV
df_ft_all$y17_19 <- as.numeric(format(df_ft_all$date, '%Y-%m-%d') %between% c('1917-03-08', '1919-08-11'))
df_ft_all_y17_19 <- subset(df_ft_all, format(as.Date(date),"%Y-%m-%d")<'1919-08-12')

# Unemployment compensation
glmarbejdsløshedsimple17_19_inf_wwi <- feglm(
  arbejdsløshedsstøtte~y17_19  + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Working day

glmarbejdsdag17_19_inf_wwi <- feglm(
  arbejdsdag~y17_19  + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Price increase compensation

glmdyrtid17_19_inf_wwi <- feglm(
  dyrtid~y17_19  + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Additional taxation

glmmerindkomstskat17_19_inf_wwi <- feglm(
  merindkomstskat~y17_19  + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Regressions, policies, parties
# Unemployment compensation
glmarbejdsløshedssimple17_19_s_inf_wwi <- feglm(
  arbejdsløshedsstøtte ~ y17_19 + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmarbejdsløshedssimple17_19_k_inf_wwi <- feglm(
  arbejdsløshedsstøtte ~ y17_19 + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmarbejdsløshedssimple17_19_v_inf_wwi <- feglm(
  arbejdsløshedsstøtte ~ y17_19 + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)),
  family = quasipoisson(),
  se = "hetero")

glmarbejdsløshedssimple17_19_r_inf_wwi <- feglm(
  arbejdsløshedsstøtte ~ y17_19 + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

# Working day
glmarbejdsdagsimple17_19_s_inf_wwi <- feglm(
  arbejdsdag ~ y17_19 + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmarbejdsdagsimple17_19_k_inf_wwi <- feglm(
  arbejdsdag ~ y17_19 + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmarbejdsdagsimple17_19_v_inf_wwi <- feglm(
  arbejdsdag ~ y17_19 + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)),
  family = quasipoisson(),
  se = "hetero")

glmarbejdsdagsimple17_19_r_inf_wwi <- feglm(
  arbejdsdag ~ y17_19 + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

# Price increase compensation

glmdyrtidsimple17_19_s_inf_wwi <- feglm(
  dyrtid ~ y17_19 + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmdyrtidsimple17_19_k_inf_wwi <- feglm(
  dyrtid ~ y17_19 + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmdyrtidsimple17_19_v_inf_wwi <- feglm(
  dyrtid ~ y17_19 + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)), 
  family = quasipoisson(),
  se = "hetero")

glmdyrtidsimple17_19_r_inf_wwi <- feglm(
  dyrtid ~ y17_19 + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

# Additional taxation
glmmerindkomstskatsimple17_19_s_inf_wwi <- feglm(
  merindkomstskat ~ y17_19 + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmmerindkomstskatsimple17_19_k_inf_wwi <- feglm(
  merindkomstskat ~ y17_19 + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmmerindkomstskatsimple17_19_v_inf_wwi <- feglm(
  merindkomstskat ~ y17_19 + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)), 
  family = quasipoisson(),
  se = "hetero")

glmmerindkomstskatsimple17_19_r_inf_wwi <- feglm(
  merindkomstskat ~ y17_19 + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

# Revolutionary terms

glmsocrevall17_19_inf_wwi <- feglm(
  socrevall~y17_19  + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Regressions, revolutionary terms, parties

glmsocrevall17_19_sinf_wwi <- feglm(
  socrevall ~ y17_19 + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmsocrevall17_19_kinf_wwi <- feglm(
  socrevall ~ y17_19 + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmsocrevall17_19_vinf_wwi <- feglm(
  socrevall ~ y17_19 + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)),
  family = quasipoisson(),
  se = "hetero")

glmsocrevall17_19_rinf_wwi <- feglm(
  socrevall ~ y17_19 + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

# Repression

glmrepress17_19_inf_wwi <- feglm(
  repress~y17_19  + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Repression, parties

glmrepress17_19_sinf_wwi <- feglm(
  repress ~ y17_19 + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmrepress17_19_kinf_wwi <- feglm(
  repress ~ y17_19 + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmrepress17_19_vinf_wwi <- feglm(
  repress ~ y17_19 + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)),
  family = quasipoisson(),
  se = "hetero")

glmrepress17_19_rinf_wwi <- feglm(
  repress ~ y17_19 + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

# Revolutionary terms and repression or co-optation

df_ft_all$socrevall_coopt <- ifelse(df_ft_all$socrevall > 0 & (df_ft_all$arbejdsløshedsstøtte > 0 | df_ft_all$dyrtid > 0 | df_ft_all$arbejdsdag > 0 | df_ft_all$merindkomstskat > 0), 1, 0)
df_ft_all$socrevall_repress <- ifelse(df_ft_all$socrevall > 0 & df_ft_all$repress > 0, 1, 0)
df_ft_all$y17_19 <- as.numeric(format(df_ft_all$date, '%Y-%m-%d') %between% c('1917-03-08', '1919-08-11'))
df_ft_all_y17_19 <- subset(df_ft_all, format(as.Date(date),"%Y-%m-%d")<'1919-08-12')
df_ft_all_y17_19$year <- as.numeric(df_ft_all_y17_19$year)
library(fixest)
library(broom)
library(ggplot2)
library(dplyr)

glmsocrevallcoopt17_19_inf_wwi <- feglm(
  socrevall_coopt~y17_19  + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

glmsocrevallrepress17_19_inf_wwi <- feglm(
  socrevall_repress~y17_19  + growth + unemp + election + inflation + n_tokens_all + wwi, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Tables, D3, aggregate

texreg(
  list(glmarbejdsløshedsimple17_19_inf_wwi, glmarbejdsdag17_19_inf_wwi, glmdyrtid17_19_inf_wwi, glmmerindkomstskat17_19_inf_wwi),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens",
    "World War I"
  ),
  custom.model.names = c("Unempl. benefits", "Working day", "Price inc. comp.", "Add. tax"),
  caption = "Unemployment support",
  stars = c(0.05, 0.01, 0.001),   include.loglik = FALSE,   include.pseudors = FALSE, caption.above = TRUE,  
)

texreg(
  list(glmrepress17_19_inf_wwi, glmsocrevall17_19_inf_wwi),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens",
    "World War I"
  ),
  custom.model.names = c("Repression", "Revolutionary terms"),
  caption = "Repression and revolutionary terms",
  stars = c(0.05, 0.01, 0.001), include.loglik = FALSE,   include.pseudors = FALSE, caption.above = TRUE,  
)

texreg(
  list(glmsocrevallcoopt17_19_inf_wwi, glmsocrevallrepress17_19_inf_wwi),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens",
    "World War I"
  ),
  custom.model.names = c("Revolutionary terms and co-optation", "Revolutionary terms and repression"),
  caption = "Revolutionary terms and co-optation or repression",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)


# Tables, D3, party level

texreg(
  list(glmarbejdsløshedssimple17_19_s_inf_wwi, glmarbejdsløshedssimple17_19_k_inf_wwi, glmarbejdsløshedssimple17_19_v_inf_wwi, glmarbejdsløshedssimple17_19_r_inf_wwi),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens",
    "World War I"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Unemployment support, parties",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmarbejdsdagsimple17_19_s_inf_wwi, glmarbejdsdagsimple17_19_k_inf_wwi, glmarbejdsdagsimple17_19_v_inf_wwi, glmarbejdsdagsimple17_19_r_inf_wwi),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens",
    "World War I"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Working day, parties",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmdyrtidsimple17_19_s_inf_wwi, glmdyrtidsimple17_19_k_inf_wwi, glmdyrtidsimple17_19_v_inf_wwi, glmdyrtidsimple17_19_r_inf_wwi),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens",
    "World War I"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Price increase compensation, parties",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmmerindkomstskatsimple17_19_s_inf_wwi, glmmerindkomstskatsimple17_19_k_inf_wwi, glmmerindkomstskatsimple17_19_v_inf_wwi, glmmerindkomstskatsimple17_19_r_inf_wwi),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens",
    "World War I"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Additional taxation, parties",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmrepress17_19_sinf_wwi, glmrepress17_19_kinf_wwi, glmrepress17_19_vinf_wwi, glmrepress17_19_rinf_wwi),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens",
    "World War I"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Repression, parties",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmsocrevall17_19_sinf_wwi, glmsocrevall17_19_kinf_wwi, glmsocrevall17_19_vinf_wwi, glmsocrevall17_19_rinf_wwi),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens",
    "World War I"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Revolutionary terms, parties",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)


# D4. Party fixed effects

df_ft_all$party_grouped <- ifelse(df_ft_all$party == 2, 2,
                                                ifelse(df_ft_all$party %in% c(3, 7, 8, 16, 101), 3,
                                                       ifelse(df_ft_all$party %in% c(4, 13, 14, 15, 103), 4,
                                                              ifelse(df_ft_all$party %in% c(5, 102), 5, df_ft_all$party)
                                                       )
                                                )
)

df_ft_all$y17_19 <- as.numeric(format(df_ft_all$date, '%Y-%m-%d') %between% c('1917-03-08', '1919-08-11'))
df_ft_all_y17_19 <- subset(df_ft_all, format(as.Date(date),"%Y-%m-%d")<'1919-08-12')


# Unemployment compensation

glmarbejdsløshedsimple17_19_inf_pfe <- feglm(
  arbejdsløshedsstøtte~y17_19  + growth + unemp + election + inflation + n_tokens_all + factor(party_grouped)-1, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Working day

glmarbejdsdag17_19_inf_pfe <- feglm(
  arbejdsdag~y17_19  + growth + unemp + election + inflation + n_tokens_all +factor(party_grouped)-1, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Price increase compensation

glmdyrtid17_19_inf_pfe <- feglm(
  dyrtid~y17_19  + growth + unemp + election + inflation + n_tokens_all + factor(party_grouped)-1, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Additional taxation

glmmerindkomstskat17_19_inf_pfe <- feglm(
  merindkomstskat~y17_19  + growth + unemp + election + inflation + n_tokens_all + factor(party_grouped)-1, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Revolutionary terms

glmsocrevall17_19_inf_pfe <- feglm(
  socrevall~y17_19  + growth + unemp + election + inflation + n_tokens_all + factor(party_grouped)-1, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Repression

glmrepress17_19_inf_pfe <- feglm(
  repress~y17_19  + growth + unemp + election + inflation + n_tokens_all + factor(party_grouped)-1, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Revolutionary terms and co-optation or repression

glmsocrevallcoopt17_19_inf_pfe <- feglm(
  socrevall_coopt~y17_19  + growth + unemp + election + inflation + n_tokens_all + factor(party_grouped)-1, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

glmsocrevallrepress17_19_inf_pfe <- feglm(
  socrevall_repress~y17_19  + growth + unemp + election + inflation + n_tokens_all + factor(party_grouped)-1, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

## Tables, D4, party fixed effects, aggregate

texreg(
  list(glmarbejdsløshedsimple17_19_inf_pfe, glmarbejdsdag17_19_inf_pfe, glmdyrtid17_19_inf_pfe, glmmerindkomstskat17_19_inf_pfe),
  custom.coef.names = c(
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens",
    "Party = Speaker",
    "Party = Soc. Dems",
    "Party = Conservatives",
    "Party = Liberals",
    "Party = Social-Liberals",
    "Party = Erhvervspartiet",
    "Party = Danmarks Retsforbund",
    "No party, left-wing ministry",
    "No party, right-wing ministry"
  ),
  custom.model.names = c("Unempl. benefits", "Working day", "Price inc. comp.", "Add. tax"),
  caption = "Co-optation",
  stars = c(0.05, 0.01, 0.001),   include.loglik = FALSE,   include.pseudors = FALSE, caption.above = TRUE,  
)

texreg(
  list(glmrepress17_19_inf_pfe, glmsocrevall17_19_inf_pfe),
  custom.coef.names = c(
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens",
    "Party = Speaker",
    "Party = Soc. Dems",
    "Party = Conservatives",
    "Party = Liberals",
    "Party = Social-Liberals",
    "Party = Erhvervspartiet",
    "Party = Danmarks Retsforbund",
    "No party, left-wing ministry",
    "No party, right-wing ministry"
  ),
  custom.model.names = c("Repression", "Revolutionary terms"),
  stars = c(0.05, 0.01, 0.001), include.loglik = FALSE,   include.pseudors = FALSE, caption.above = TRUE,  
)

texreg(
  list(glmsocrevallcoopt17_19_inf_pfe, glmsocrevallrepress17_19_inf_pfe),
  custom.coef.names = c(
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens",
    "Party = Speaker",
    "Party = Soc. Dems",
    "Party = Conservatives",
    "Party = Liberals",
    "Party = Social-Liberals",
    "Party = Erhvervspartiet",
    "Party = Danmarks Retsforbund",
    "No party, left-wing ministry",
    "No party, right-wing ministry"
  ),
  custom.model.names = c("Revolutionary terms and co-optation", "Revolutionary terms and repression"),
  caption = "Revolutionary terms and co-optation or repression",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)


# D5. Year fixed effects

## Making year cluster
breaks <- seq(as.Date('1910-01-01'), as.Date('1917-03-07'), length.out = 6)
df_ft_all_y17_19 <- df_ft_all_y17_19 %>%
  mutate(year_cluster = cut(date, breaks, labels = FALSE))
df_ft_all_y17_19$year_cluster[df_ft_all_y17_19$date >= as.Date('1917-03-08') &
                                df_ft_all_y17_19$date <= as.Date('1919-08-11')] <- 'Revolution'
df_ft_all_y17_19$year_cluster <- factor(df_ft_all_y17_19$year_cluster)
df_ft_all_y17_19$year_cluster <- relevel(df_ft_all_y17_19$year_cluster, ref = "5")


## Unemployment compensation

glmarbejdsløshedsimple17_19_inf_fe <- feglm(
  arbejdsløshedsstøtte~ growth + unemp + election + inflation + n_tokens_all + factor(year_cluster), 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

## Working day

glmarbejdsdag17_19_inf_fe <- feglm(
  arbejdsdag~ + growth + unemp + election + inflation + n_tokens_all +factor(year_cluster), 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

## Price increase compensation

glmdyrtid17_19_inf_fe <- feglm(
  dyrtid~ + growth + unemp + election + inflation + n_tokens_all + factor(year_cluster), 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

## Additional taxation

glmmerindkomstskat17_19_inf_fe <- feglm(
  merindkomstskat~ growth + unemp + election + inflation + n_tokens_all + factor(year_cluster), 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

## Revolutionary terms

glmsocrevall17_19_inf_fe <- feglm(
  socrevall~ growth + unemp + election + inflation + n_tokens_all + factor(year_cluster), 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

## Repression

glmrepress17_19_inf_fe <- feglm(
  repress~ growth + unemp + election + inflation + n_tokens_all + factor(year_cluster), 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

## Tables

texreg(
  list(glmarbejdsløshedsimple17_19_inf_fe, glmarbejdsdag17_19_inf_fe, glmdyrtid17_19_inf_fe, glmmerindkomstskat17_19_inf_fe),
  custom.coef.names = c(
    "(Intercept)",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens",
    "Year cluster 1",
    "Year cluster 2",
    "Year cluster 3",
    "Year cluster 4",
    "Revolutionary period"
  ),
  custom.model.names = c("Unempl. benefits", "Working day", "Price inc. comp.", "Add. tax"),
  caption = "Co-optation",
  stars = c(0.05, 0.01, 0.001),   include.loglik = FALSE,   include.pseudors = FALSE, caption.above = TRUE,  
)

texreg(
  list(glmrepress17_19_inf_fe, glmsocrevall17_19_inf_fe),
  custom.coef.names = c(
    "(Intercept)",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens",
    "Year cluster 1",
    "Year cluster 2",
    "Year cluster 3",
    "Year cluster 4",
    "Revolutionary period"
  ),
  custom.model.names = c("Repression", "Revolutionary terms"),
  stars = c(0.05, 0.01, 0.001), include.loglik = FALSE,   include.pseudors = FALSE, caption.above = TRUE,  
)


# D6. Poisson 

## Poisson 

# Unemployment compensation
p_glmarbejdsløshedsimple17_19_inf <- feglm(
  arbejdsløshedsstøtte~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19,
  family = poisson(),
  se = "hetero")

# Working day
p_glmarbejdsdag17_19_inf <- feglm(
  arbejdsdag~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19,
  family = poisson(),
  se = "hetero")

# Price increase compensation
p_glmdyrtid17_19_inf <- feglm(
  dyrtid~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19,
  family = poisson(),
  se = "hetero")

# Additional taxation
p_glmmerindkomstskat17_19_inf <- feglm(
  merindkomstskat~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19,
  family = poisson(),
  se = "hetero")

# Regressions, policies, parties
# Unemployment compensation
p_glmarbejdsløshedssimple17_19_s_inf <- feglm(
  arbejdsløshedsstøtte ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = poisson(),
  se = "hetero")

p_glmarbejdsløshedssimple17_19_k_inf <- feglm(
  arbejdsløshedsstøtte ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = poisson(),
  se = "hetero")

p_glmarbejdsløshedssimple17_19_v_inf <- feglm(
  arbejdsløshedsstøtte ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)),
  family = poisson(),
  se = "hetero")

p_glmarbejdsløshedssimple17_19_r_inf <- feglm(
  arbejdsløshedsstøtte ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = poisson(),
  se = "hetero")

# Working day
p_glmarbejdsdagsimple17_19_s_inf <- feglm(
  arbejdsdag ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = poisson(),
  se = "hetero")

p_glmarbejdsdagsimple17_19_k_inf <- feglm(
  arbejdsdag ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = poisson(),
  se = "hetero")

p_glmarbejdsdagsimple17_19_v_inf <- feglm(
  arbejdsdag ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)),
  family = poisson(),
  se = "hetero")

p_glmarbejdsdagsimple17_19_r_inf <- feglm(
  arbejdsdag ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = poisson(),
  se = "hetero")

# Price increase compensation

p_glmdyrtidsimple17_19_s_inf <- feglm(
  dyrtid ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = poisson(),
  se = "hetero")

p_glmdyrtidsimple17_19_k_inf <- feglm(
  dyrtid ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = poisson(),
  se = "hetero")

p_glmdyrtidsimple17_19_v_inf <- feglm(
  dyrtid ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)), 
  family = poisson(),
  se = "hetero")

p_glmdyrtidsimple17_19_r_inf <- feglm(
  dyrtid ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = poisson(),
  se = "hetero")

# Additional taxation
p_glmmerindkomstskatsimple17_19_s_inf <- feglm(
  merindkomstskat ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = poisson(),
  se = "hetero")

p_glmmerindkomstskatsimple17_19_k_inf <- feglm(
  merindkomstskat ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = poisson(),
  se = "hetero")

p_glmmerindkomstskatsimple17_19_v_inf <- feglm(
  merindkomstskat ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)), 
  family = poisson(),
  se = "hetero")

p_glmmerindkomstskatsimple17_19_r_inf <- feglm(
  merindkomstskat ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = poisson(),
  se = "hetero")

# Revolutionary terms

p_glmsocrevall17_19_inf <- feglm(
  socrevall~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19,
  family = poisson(),
  se = "hetero")

# Regressions, revolutionary terms, parties

p_glmsocrevall17_19_sinf <- feglm(
  socrevall ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = poisson(),
  se = "hetero")

p_glmsocrevall17_19_kinf <- feglm(
  socrevall ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = poisson(),
  se = "hetero")

p_glmsocrevall17_19_vinf <- feglm(
  socrevall ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)),
  family = poisson(),
  se = "hetero")

p_glmsocrevall17_19_rinf <- feglm(
  socrevall ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = poisson(),
  se = "hetero")

# Repression

p_glmrepress17_19_inf <- feglm(
  repress~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19,
  family = poisson(),
  se = "hetero")

# Repression, parties

p_glmrepress17_19_sinf <- feglm(
  repress ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = poisson(),
  se = "hetero")

p_glmrepress17_19_kinf <- feglm(
  repress ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = poisson(),
  se = "hetero")

p_glmrepress17_19_vinf <- feglm(
  repress ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)),
  family = poisson(),
  se = "hetero")

p_glmrepress17_19_rinf <- feglm(
  repress ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = poisson(),
  se = "hetero")

# Revolutionary terms and repression or co-optation

df_ft_all$socrevall_coopt <- ifelse(df_ft_all$socrevall > 0 & (df_ft_all$arbejdsløshedsstøtte > 0 | df_ft_all$dyrtid > 0 | df_ft_all$arbejdsdag > 0 | df_ft_all$merindkomstskat > 0), 1, 0)
df_ft_all$socrevall_repress <- ifelse(df_ft_all$socrevall > 0 & df_ft_all$repress > 0, 1, 0)
df_ft_all$y17_19 <- as.numeric(format(df_ft_all$date, '%Y-%m-%d') %between% c('1917-03-08', '1919-08-11'))
df_ft_all_y17_19 <- subset(df_ft_all, format(as.Date(date),"%Y-%m-%d")<'1919-08-12')
df_ft_all_y17_19$year <- as.numeric(df_ft_all_y17_19$year)
library(fixest)
library(broom)
library(ggplot2)
library(dplyr)

p_glmsocrevallcoopt17_19_inf <- feglm(
  socrevall_coopt~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19,
  family = poisson(),
  se = "hetero")

p_glmsocrevallrepress17_19_inf <- feglm(
  socrevall_repress~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19,
  family = poisson(),
  se = "hetero")

## D6, tables, Poisson

texreg(
  list(p_glmarbejdsløshedsimple17_19_inf, p_glmarbejdsdag17_19_inf, p_glmdyrtid17_19_inf, p_glmmerindkomstskat17_19_inf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Unempl. benefits", "Working day", "Price inc. comp.", "Add. tax"),
  caption = "Co-optation",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(p_glmrepress17_19_inf, p_glmsocrevall17_19_inf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Repression", "Revolutionary terms"),
  caption = "Repression and revolutionary terms",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(p_glmsocrevall17_19_inf, p_glmrepress17_19_inf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Co-optation", "Repress"),
  caption = "Revolutionary terms and co-optation or repression",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

# D6. Tables, parties, Poisson

texreg(
  list(p_glmarbejdsløshedssimple17_19_s_inf, p_glmarbejdsløshedssimple17_19_k_inf, p_glmarbejdsløshedssimple17_19_v_inf, p_glmarbejdsløshedssimple17_19_r_inf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Unemployment support, parties",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(p_glmarbejdsdagsimple17_19_s_inf, p_glmarbejdsdagsimple17_19_k_inf, p_glmarbejdsdagsimple17_19_v_inf, p_glmarbejdsdagsimple17_19_r_inf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Working day, parties",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(p_glmdyrtidsimple17_19_s_inf, p_glmdyrtidsimple17_19_k_inf, p_glmdyrtidsimple17_19_v_inf, p_glmdyrtidsimple17_19_r_inf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Price increase compensation, parties",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(p_glmmerindkomstskatsimple17_19_s_inf, p_glmmerindkomstskatsimple17_19_k_inf, p_glmmerindkomstskatsimple17_19_v_inf, p_glmmerindkomstskatsimple17_19_r_inf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Additional taxation, parties",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(p_glmrepress17_19_sinf, p_glmrepress17_19_kinf, p_glmrepress17_19_vinf, p_glmrepress17_19_rinf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Repression, parties",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(p_glmsocrevall17_19_sinf, p_glmsocrevall17_19_kinf, p_glmsocrevall17_19_vinf, p_glmsocrevall17_19_rinf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Revolutionary terms, parties",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

# D7. Measurement error (FOR APPENDIX ON MEASUREMENT ERROR, SHOWING THE CONFIDENCE INTERVALS AND ESTIMATE AFTER REMOVING ONE DATE AT A TIME)

# Unemployment support

df_ft_all$y17_19 <- as.numeric(format(df_ft_all$date, '%Y-%m-%d') %between% c('1917-03-08', '1919-08-11'))
df_ft_all_y17_19 <- subset(df_ft_all, format(as.Date(date),"%Y-%m-%d")<'1919-08-12')
df_ft_all_y17_19$year <- as.numeric(df_ft_all_y17_19$year)
breaks <- seq(min(df_ft_all_y17_19$year), max(df_ft_all_y17_19$year) + 2, by = 2)
df_ft_all_y17_19$year_cluster <- findInterval(df_ft_all_y17_19$year, vec = breaks)

results_list <- list()
iteration_counter <- 0

# Initialize a set to store unique dates
unique_dates_removed <- c()
dates_to_remove <- df_ft_all_y17_19$date[df_ft_all_y17_19$y17_19 == 1]

for (date_to_remove in dates_to_remove) {
  if (!(date_to_remove %in% unique_dates_removed)) {
    iteration_counter <- iteration_counter + 1  # Increment the iteration counter
    
    cat("Iteration: ", iteration_counter, "\n")  # Print the current iteration number
    
    # Add the unique date to the set
    unique_dates_removed <- c(unique_dates_removed, date_to_remove)
    
    # Create a subset of the dataset without the unique date
    df_subset <- df_ft_all_y17_19[df_ft_all_y17_19$date != date_to_remove, ]
    
    # Fit the regression model
    model <- feglm(
      arbejdsløshedsstøtte ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
      data = df_subset,
      family = quasipoisson(),
      se = "hetero"
    )
    
    # Store the results in a list along with the iteration number
    results_list[[as.character(iteration_counter)]] <- list(iteration = iteration_counter, summary = summary(model))
  }
}

# Create an empty list to store y17_19 estimates and confidence intervals
y17_19_estimates <- list()
y17_19_ci <- list()

# Extract y17_19 estimates and confidence intervals for each run
for (run_number in 1:length(results_list)) {
  run_results <- results_list[[as.character(run_number)]]$summary
  y17_19_estimates[[run_number]] <- coef(run_results)["y17_19"]
  y17_19_ci[[run_number]] <- confint(run_results, "y17_19")
}

# Create a data frame to store the data
y17_19_data <- data.frame(
  Date = unique(dates_to_remove),
  Estimate = sapply(y17_19_estimates, function(x) x[1]),
  Lower_CI = sapply(y17_19_ci, function(x) x[1, 1]),
  Upper_CI = sapply(y17_19_ci, function(x) x[1, 2])
)

# Sort the data frame by Date
y17_19_data <- y17_19_data[order(y17_19_data$Date), ]

# Create the plot
library(ggplot2)
meas_error_arbstøt <- ggplot(y17_19_data, aes(x = Date, y = Estimate)) +
  geom_line() +
  geom_ribbon(aes(ymin = Lower_CI, ymax = Upper_CI), alpha = 0.2) +
  labs(x = "Date", y = "Estimate") +
  ggtitle("Unempl. benefits") +
  theme_minimal()

# Price increase compensation

df_ft_all$y17_19 <- as.numeric(format(df_ft_all$date, '%Y-%m-%d') %between% c('1917-03-08', '1919-08-11'))
df_ft_all_y17_19 <- subset(df_ft_all, format(as.Date(date),"%Y-%m-%d")<'1919-08-12')
df_ft_all_y17_19$year <- as.numeric(df_ft_all_y17_19$year)
breaks <- seq(min(df_ft_all_y17_19$year), max(df_ft_all_y17_19$year) + 2, by = 2)
df_ft_all_y17_19$year_cluster <- findInterval(df_ft_all_y17_19$year, vec = breaks)

results_list <- list()
iteration_counter <- 0

# Initialize a set to store unique dates
unique_dates_removed <- c()
dates_to_remove <- df_ft_all_y17_19$date[df_ft_all_y17_19$y17_19 == 1]

for (date_to_remove in dates_to_remove) {
  if (!(date_to_remove %in% unique_dates_removed)) {
    iteration_counter <- iteration_counter + 1  # Increment the iteration counter
    
    cat("Iteration: ", iteration_counter, "\n")  # Print the current iteration number
    
    # Add the unique date to the set
    unique_dates_removed <- c(unique_dates_removed, date_to_remove)
    
    # Create a subset of the dataset without the unique date
    df_subset <- df_ft_all_y17_19[df_ft_all_y17_19$date != date_to_remove, ]
    
    # Fit the regression model
    model <- feglm(
      dyrtid ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
      data = df_subset,
      family = quasipoisson(),
      se = "hetero"
    )
    
    # Store the results in a list along with the iteration number
    results_list[[as.character(iteration_counter)]] <- list(iteration = iteration_counter, summary = summary(model))
  }
}



# Create an empty list to store y17_19 estimates and confidence intervals
y17_19_estimates <- list()
y17_19_ci <- list()

# Extract y17_19 estimates and confidence intervals for each run
for (run_number in 1:length(results_list)) {
  run_results <- results_list[[as.character(run_number)]]$summary
  y17_19_estimates[[run_number]] <- coef(run_results)["y17_19"]
  y17_19_ci[[run_number]] <- confint(run_results, "y17_19")
}

# Create a data frame to store the data
y17_19_data <- data.frame(
  Date = unique(dates_to_remove),
  Estimate = sapply(y17_19_estimates, function(x) x[1]),
  Lower_CI = sapply(y17_19_ci, function(x) x[1, 1]),
  Upper_CI = sapply(y17_19_ci, function(x) x[1, 2])
)

# Sort the data frame by Date
y17_19_data <- y17_19_data[order(y17_19_data$Date), ]

# Create the plot
library(ggplot2)
meas_error_dyrtid <- ggplot(y17_19_data, aes(x = Date, y = Estimate)) +
  geom_line() +
  geom_ribbon(aes(ymin = Lower_CI, ymax = Upper_CI), alpha = 0.2) +
  labs(x = "Date", y = "Estimate") +
  ggtitle("Price incr. compensation") +
  theme_minimal()

# Working day

df_ft_all$y17_19 <- as.numeric(format(df_ft_all$date, '%Y-%m-%d') %between% c('1917-03-08', '1919-08-11'))
df_ft_all_y17_19 <- subset(df_ft_all, format(as.Date(date),"%Y-%m-%d")<'1919-08-12')
df_ft_all_y17_19$year <- as.numeric(df_ft_all_y17_19$year)
breaks <- seq(min(df_ft_all_y17_19$year), max(df_ft_all_y17_19$year) + 2, by = 2)
df_ft_all_y17_19$year_cluster <- findInterval(df_ft_all_y17_19$year, vec = breaks)

results_list <- list()
iteration_counter <- 0

# Initialize a set to store unique dates
unique_dates_removed <- c()
dates_to_remove <- df_ft_all_y17_19$date[df_ft_all_y17_19$y17_19 == 1]

for (date_to_remove in dates_to_remove) {
  if (!(date_to_remove %in% unique_dates_removed)) {
    iteration_counter <- iteration_counter + 1  # Increment the iteration counter
    
    cat("Iteration: ", iteration_counter, "\n")  # Print the current iteration number
    
    # Add the unique date to the set
    unique_dates_removed <- c(unique_dates_removed, date_to_remove)
    
    # Create a subset of the dataset without the unique date
    df_subset <- df_ft_all_y17_19[df_ft_all_y17_19$date != date_to_remove, ]
    
    # Fit the regression model
    model <- feglm(
      arbejdsdag ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
      data = df_subset,
      family = quasipoisson(),
      se = "hetero"
    )
    
    # Store the results in a list along with the iteration number
    results_list[[as.character(iteration_counter)]] <- list(iteration = iteration_counter, summary = summary(model))
  }
}



# Create an empty list to store y17_19 estimates and confidence intervals
y17_19_estimates <- list()
y17_19_ci <- list()

# Extract y17_19 estimates and confidence intervals for each run
for (run_number in 1:length(results_list)) {
  run_results <- results_list[[as.character(run_number)]]$summary
  y17_19_estimates[[run_number]] <- coef(run_results)["y17_19"]
  y17_19_ci[[run_number]] <- confint(run_results, "y17_19")
}

# Create a data frame to store the data
y17_19_data <- data.frame(
  Date = unique(dates_to_remove),
  Estimate = sapply(y17_19_estimates, function(x) x[1]),
  Lower_CI = sapply(y17_19_ci, function(x) x[1, 1]),
  Upper_CI = sapply(y17_19_ci, function(x) x[1, 2])
)

# Sort the data frame by Date
y17_19_data <- y17_19_data[order(y17_19_data$Date), ]

# Create the plot
library(ggplot2)
meas_error_arbejdsdag <- ggplot(y17_19_data, aes(x = Date, y = Estimate)) +
  geom_line() +
  geom_ribbon(aes(ymin = Lower_CI, ymax = Upper_CI), alpha = 0.2) +
  labs(x = "Date", y = "Estimate") +
  ggtitle("Working day") +
  theme_minimal()

# Additional taxation

df_ft_all$y17_19 <- as.numeric(format(df_ft_all$date, '%Y-%m-%d') %between% c('1917-03-08', '1919-08-11'))
df_ft_all_y17_19 <- subset(df_ft_all, format(as.Date(date),"%Y-%m-%d")<'1919-08-12')
df_ft_all_y17_19$year <- as.numeric(df_ft_all_y17_19$year)
breaks <- seq(min(df_ft_all_y17_19$year), max(df_ft_all_y17_19$year) + 2, by = 2)
df_ft_all_y17_19$year_cluster <- findInterval(df_ft_all_y17_19$year, vec = breaks)

results_list <- list()
iteration_counter <- 0

# Initialize a set to store unique dates
unique_dates_removed <- c()
dates_to_remove <- df_ft_all_y17_19$date[df_ft_all_y17_19$y17_19 == 1]

for (date_to_remove in dates_to_remove) {
  if (!(date_to_remove %in% unique_dates_removed)) {
    iteration_counter <- iteration_counter + 1  # Increment the iteration counter
    
    cat("Iteration: ", iteration_counter, "\n")  # Print the current iteration number
    
    # Add the unique date to the set
    unique_dates_removed <- c(unique_dates_removed, date_to_remove)
    
    # Create a subset of the dataset without the unique date
    df_subset <- df_ft_all_y17_19[df_ft_all_y17_19$date != date_to_remove, ]
    
    # Fit the regression model
    model <- feglm(
      merindkomstskat ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
      data = df_subset,
      family = quasipoisson(),
      se = "hetero"
    )
    
    # Store the results in a list along with the iteration number
    results_list[[as.character(iteration_counter)]] <- list(iteration = iteration_counter, summary = summary(model))
  }
}



# Create an empty list to store y17_19 estimates and confidence intervals
y17_19_estimates <- list()
y17_19_ci <- list()

# Extract y17_19 estimates and confidence intervals for each run
for (run_number in 1:length(results_list)) {
  run_results <- results_list[[as.character(run_number)]]$summary
  y17_19_estimates[[run_number]] <- coef(run_results)["y17_19"]
  y17_19_ci[[run_number]] <- confint(run_results, "y17_19")
}

# Create a data frame to store the data
y17_19_data <- data.frame(
  Date = unique(dates_to_remove),
  Estimate = sapply(y17_19_estimates, function(x) x[1]),
  Lower_CI = sapply(y17_19_ci, function(x) x[1, 1]),
  Upper_CI = sapply(y17_19_ci, function(x) x[1, 2])
)

# Sort the data frame by Date
y17_19_data <- y17_19_data[order(y17_19_data$Date), ]

# Create the plot
library(ggplot2)
meas_error_merindkomstskat <- ggplot(y17_19_data, aes(x = Date, y = Estimate)) +
  geom_line() +
  geom_ribbon(aes(ymin = Lower_CI, ymax = Upper_CI), alpha = 0.2) +
  labs(x = "Date", y = "Estimate") +
  ggtitle("Add. tax") +
  theme_minimal()


# Repression

df_ft_all$y17_19 <- as.numeric(format(df_ft_all$date, '%Y-%m-%d') %between% c('1917-03-08', '1919-08-11'))
df_ft_all_y17_19 <- subset(df_ft_all, format(as.Date(date),"%Y-%m-%d")<'1919-08-12')
df_ft_all_y17_19$year <- as.numeric(df_ft_all_y17_19$year)
breaks <- seq(min(df_ft_all_y17_19$year), max(df_ft_all_y17_19$year) + 2, by = 2)
df_ft_all_y17_19$year_cluster <- findInterval(df_ft_all_y17_19$year, vec = breaks)

results_list <- list()
iteration_counter <- 0

# Initialize a set to store unique dates
unique_dates_removed <- c()
dates_to_remove <- df_ft_all_y17_19$date[df_ft_all_y17_19$y17_19 == 1]

for (date_to_remove in dates_to_remove) {
  if (!(date_to_remove %in% unique_dates_removed)) {
    iteration_counter <- iteration_counter + 1  # Increment the iteration counter
    
    cat("Iteration: ", iteration_counter, "\n")  # Print the current iteration number
    
    # Add the unique date to the set
    unique_dates_removed <- c(unique_dates_removed, date_to_remove)
    
    # Create a subset of the dataset without the unique date
    df_subset <- df_ft_all_y17_19[df_ft_all_y17_19$date != date_to_remove, ]
    
    # Fit the regression model
    model <- feglm(
      repress ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
      data = df_subset,
      family = quasipoisson(),
      se = "hetero"
    )
    
    # Store the results in a list along with the iteration number
    results_list[[as.character(iteration_counter)]] <- list(iteration = iteration_counter, summary = summary(model))
  }
}



# Create an empty list to store y17_19 estimates and confidence intervals
y17_19_estimates <- list()
y17_19_ci <- list()

# Extract y17_19 estimates and confidence intervals for each run
for (run_number in 1:length(results_list)) {
  run_results <- results_list[[as.character(run_number)]]$summary
  y17_19_estimates[[run_number]] <- coef(run_results)["y17_19"]
  y17_19_ci[[run_number]] <- confint(run_results, "y17_19")
}

# Create a data frame to store the data
y17_19_data <- data.frame(
  Date = unique(dates_to_remove),
  Estimate = sapply(y17_19_estimates, function(x) x[1]),
  Lower_CI = sapply(y17_19_ci, function(x) x[1, 1]),
  Upper_CI = sapply(y17_19_ci, function(x) x[1, 2])
)

# Sort the data frame by Date
y17_19_data <- y17_19_data[order(y17_19_data$Date), ]

# Create the plot
library(ggplot2)
meas_error_repress <- ggplot(y17_19_data, aes(x = Date, y = Estimate)) +
  geom_line() +
  geom_ribbon(aes(ymin = Lower_CI, ymax = Upper_CI), alpha = 0.2) +
  labs(x = "Date", y = "Estimate") +
  ggtitle("Repression") +
  theme_minimal()


# Revolutionary terms

df_ft_all$y17_19 <- as.numeric(format(df_ft_all$date, '%Y-%m-%d') %between% c('1917-03-08', '1919-08-11'))
df_ft_all_y17_19 <- subset(df_ft_all, format(as.Date(date),"%Y-%m-%d")<'1919-08-12')
df_ft_all_y17_19$year <- as.numeric(df_ft_all_y17_19$year)
breaks <- seq(min(df_ft_all_y17_19$year), max(df_ft_all_y17_19$year) + 2, by = 2)
df_ft_all_y17_19$year_cluster <- findInterval(df_ft_all_y17_19$year, vec = breaks)

results_list <- list()
iteration_counter <- 0

# Initialize a set to store unique dates
unique_dates_removed <- c()
dates_to_remove <- df_ft_all_y17_19$date[df_ft_all_y17_19$y17_19 == 1]

for (date_to_remove in dates_to_remove) {
  if (!(date_to_remove %in% unique_dates_removed)) {
    iteration_counter <- iteration_counter + 1  # Increment the iteration counter
    
    cat("Iteration: ", iteration_counter, "\n")  # Print the current iteration number
    
    # Add the unique date to the set
    unique_dates_removed <- c(unique_dates_removed, date_to_remove)
    
    # Create a subset of the dataset without the unique date
    df_subset <- df_ft_all_y17_19[df_ft_all_y17_19$date != date_to_remove, ]
    
    # Fit the regression model
    model <- feglm(
      socrevall ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
      data = df_subset,
      family = quasipoisson(),
      se = "hetero"
    )
    
    # Store the results in a list along with the iteration number
    results_list[[as.character(iteration_counter)]] <- list(iteration = iteration_counter, summary = summary(model))
  }
}

# Create an empty list to store y17_19 estimates and confidence intervals
y17_19_estimates <- list()
y17_19_ci <- list()

# Extract y17_19 estimates and confidence intervals for each run
for (run_number in 1:length(results_list)) {
  run_results <- results_list[[as.character(run_number)]]$summary
  y17_19_estimates[[run_number]] <- coef(run_results)["y17_19"]
  y17_19_ci[[run_number]] <- confint(run_results, "y17_19")
}

# Create a data frame to store the data
y17_19_data <- data.frame(
  Date = unique(dates_to_remove),
  Estimate = sapply(y17_19_estimates, function(x) x[1]),
  Lower_CI = sapply(y17_19_ci, function(x) x[1, 1]),
  Upper_CI = sapply(y17_19_ci, function(x) x[1, 2])
)

# Sort the data frame by Date
y17_19_data <- y17_19_data[order(y17_19_data$Date), ]

# Create the plot
library(ggplot2)
meas_error_socrevall <- ggplot(y17_19_data, aes(x = Date, y = Estimate)) +
  geom_line() +
  geom_ribbon(aes(ymin = Lower_CI, ymax = Upper_CI), alpha = 0.2) +
  labs(x = "Date", y = "Estimate") +
  ggtitle("Revolutionary terms") +
  theme_minimal()

library(gridExtra)
meas_error_plot <- grid.arrange(meas_error_arbstøt, meas_error_arbejdsdag, meas_error_dyrtid, meas_error_merindkomstskat, meas_error_repress, meas_error_socrevall, ncol = 2, nrow = 3)
ggsave("FOLDER PATH", plot = meas_error_plot, width = 10, height = 8)



# D8. Robustness using Wordscores subset

setwd("FOLDER PATH")

load("/df_ws_dummy.RData")

## Regressions

ws_arbejdsløshedsstøtte <- feglm(
  arbejdsløshedsstøtte~y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ws_dummy_1,
  family = quasipoisson(),
  se = "hetero")

ws_arbejdsdag <- feglm(
  arbejdsdag~y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ws_dummy_1,
  family = quasipoisson(),
  se = "hetero")

ws_dyrtid <- feglm(
  dyrtid~y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ws_dummy_1,
  family = quasipoisson(),
  se = "hetero")

ws_merindkomstskat <- feglm(
  merindkomstskat~y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ws_dummy_1,
  family = quasipoisson(),
  se = "hetero")

ws_socrevall_coopt <- feglm(
  socrevall_coopt~y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ws_dummy_1,
  family = quasipoisson(),
  se = "hetero")

## Table

texreg(
  list(ws_arbejdsløshedsstøtte, ws_arbejdsdag, ws_dyrtid, ws_merindkomstskat),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Unempl. benefits", "Working day", "Price inc. comp.", "Add. taxation"),
  caption = "Co-optation signaling, robustness to Wordscore subset I",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)


texreg(
  list(ws_socrevall_coopt),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Revol. terms and co-opt."),
  caption = "Co-optation signaling, robustness to Wordscore subset II",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

# APPENDIX D9 - ELECTION PERIOD AND OPENING OF PARLIAMENTARY YEAR

detach("package:plyr", unload = TRUE)
library(dplyr)

# ELECTION PERIODS

## REVOLUTIONARY OPPORTUNISM

# Create a new column for Year-Month
df_ft_all_subset <- df_ft_all %>%
  mutate(month_year = format(as.Date(date), "%Y-%m"))

# Aggregate the socrevall values by Year-Month
df_aggregated <- df_ft_all_subset %>%
  group_by(month_year) %>%
  summarise(
    total_socrevall = sum(socrevall),
    total_tokens = sum(n_tokens)
  ) %>%
  ungroup()


# Filter the data for the years 1917 to 1919
df_filtered <- df_aggregated %>%
  filter(month_year >= "1917-10" & month_year <= "1918-09")

# Using single dates

df_filtered <- df_ft_all %>%
  filter(date >= as.Date("1917-10-01") & date <= as.Date("1918-12-01"))

# # Ensure the date column is in Date format
# df_filtered$date <- as.Date(df_filtered$date, format = "%Y-%m-%d")

# Define the date ranges for the three groups
start_date <- as.Date("1918-02-05")
end_date <- as.Date("1918-04-22")

# Calculate X_dates as the number of dates between start_date and end_date
X_dates <- as.integer(difftime(end_date, start_date, units = "days")) + 1

# Define the date ranges for the other groups
group1_start <- start_date - X_dates
group1_end <- start_date - 1

group3_start <- end_date + 1
group3_end <- end_date + X_dates

# Assign the group identifiers
df_filtered$election_group <- with(df_filtered, ifelse(date >= group1_start & date <= group1_end, "Pre-election",
                                                       ifelse(date >= start_date & date <= end_date, "Election period",
                                                              ifelse(date >= group3_start & date <= group3_end, "Post-election", NA))))

df_filtered <- df_filtered[!is.na(df_filtered$election_group), ]


aggregated_data <- df_filtered %>%
  group_by(election_group) %>%
  summarise(
    total_socrevall = sum(socrevall, na.rm = TRUE),
    total_tokens = sum(n_tokens)
  )

aggregated_data$socrevall_per_toks <-  aggregated_data$total_socrevall/aggregated_data$total_tokens

aggregated_data$election_group <- factor(aggregated_data$election_group, 
                                         levels = c("Pre-election", "Election period", "Post-election"))

p_socrevall_per_toks <- ggplot(aggregated_data, aes(x = election_group, y = socrevall_per_toks)) +
  geom_bar(stat = "identity") +
  labs(title = "Revolutionary terms, per number of tokens for period",
       x = "Election Group",
       y = "Total") +
  theme_minimal()

## CO-OPTATION

df_ft_all$coopt_aggregate <- df_ft_all$socrevall + df_ft_all$arbejdsløshedsstøtte + df_ft_all$dyrtid + df_ft_all$arbejdsdag + df_ft_all$merindkomstskat

# Create a new column for Year-Month
df_ft_all_subset <- df_ft_all %>%
  mutate(month_year = format(as.Date(date), "%Y-%m"))

# Aggregate the socrevall values by Year-Month
df_aggregated <- df_ft_all_subset %>%
  group_by(month_year) %>%
  summarise(coopt_aggregate = sum(coopt_aggregate)) %>%
  ungroup()

# Filter the data for the years 1917 to 1919
df_filtered <- df_aggregated %>%
  filter(month_year >= "1917-10" & month_year <= "1918-09")

# Using single dates

df_filtered <- df_ft_all %>%
  filter(date >= as.Date("1917-10-01") & date <= as.Date("1918-12-01"))

# # Ensure the date column is in Date format
# df_filtered$date <- as.Date(df_filtered$date, format = "%Y-%m-%d")

# Define the date ranges for the three groups
start_date <- as.Date("1918-02-05")
end_date <- as.Date("1918-04-22")

# Calculate X_dates as the number of dates between start_date and end_date
X_dates <- as.integer(difftime(end_date, start_date, units = "days")) + 1

# Define the date ranges for the other groups
group1_start <- start_date - X_dates
group1_end <- start_date - 1

group3_start <- end_date + 1
group3_end <- end_date + X_dates

# Assign the group identifiers
df_filtered$election_group <- with(df_filtered, ifelse(date >= group1_start & date <= group1_end, "Pre-election",
                                                       ifelse(date >= start_date & date <= end_date, "Election period",
                                                              ifelse(date >= group3_start & date <= group3_end, "Post-election", NA))))

df_filtered <- df_filtered[!is.na(df_filtered$election_group), ]


aggregated_data <- df_filtered %>%
  group_by(election_group) %>%
  summarise(
    total_coopt_aggregate = sum(coopt_aggregate, na.rm = TRUE),
    total_tokens = sum(n_tokens)
  )

aggregated_data$coopt_per_toks <-  aggregated_data$total_coopt_aggregate/aggregated_data$total_tokens

aggregated_data$election_group <- factor(aggregated_data$election_group, 
                                         levels = c("Pre-election", "Election period", "Post-election"))

p_coopt_per_toks <- ggplot(aggregated_data, aes(x = election_group, y = coopt_per_toks)) +
  geom_bar(stat = "identity") +
  labs(title = "Co-optation, per number of tokens for period",
       x = "Election Group",
       y = "Total") +
  theme_minimal()

## REPRESSION

# Create a new column for Year-Month
df_ft_all_subset <- df_ft_all %>%
  mutate(month_year = format(as.Date(date), "%Y-%m"))

# Aggregate the socrevall values by Year-Month
df_aggregated <- df_ft_all_subset %>%
  group_by(month_year) %>%
  summarise(repress_aggregate = sum(repress)) %>%
  ungroup()

# Filter the data for the years 1917 to 1919
df_filtered <- df_aggregated %>%
  filter(month_year >= "1917-10" & month_year <= "1918-09")

# Using single dates

df_filtered <- df_ft_all %>%
  filter(date >= as.Date("1917-10-01") & date <= as.Date("1918-12-01"))

# # Ensure the date column is in Date format
# df_filtered$date <- as.Date(df_filtered$date, format = "%Y-%m-%d")

# Define the date ranges for the three groups
start_date <- as.Date("1918-02-05")
end_date <- as.Date("1918-04-22")

# Calculate X_dates as the number of dates between start_date and end_date
X_dates <- as.integer(difftime(end_date, start_date, units = "days")) + 1

# Define the date ranges for the other groups
group1_start <- start_date - X_dates
group1_end <- start_date - 1

group3_start <- end_date + 1
group3_end <- end_date + X_dates

# Assign the group identifiers
df_filtered$election_group <- with(df_filtered, ifelse(date >= group1_start & date <= group1_end, "Pre-election",
                                                       ifelse(date >= start_date & date <= end_date, "Election period",
                                                              ifelse(date >= group3_start & date <= group3_end, "Post-election", NA))))

df_filtered <- df_filtered[!is.na(df_filtered$election_group), ]


aggregated_data <- df_filtered %>%
  group_by(election_group) %>%
  summarise(
    total_repress_aggregate = sum(repress, na.rm = TRUE),
    total_tokens = sum(n_tokens)
  )

aggregated_data$repress_per_toks <-  aggregated_data$total_repress_aggregate/aggregated_data$total_tokens

aggregated_data$election_group <- factor(aggregated_data$election_group, 
                                         levels = c("Pre-election", "Election period", "Post-election"))

p_repress_per_toks <- ggplot(aggregated_data, aes(x = election_group, y = repress_per_toks)) +
  geom_bar(stat = "identity") +
  labs(title = "Repression, per number of tokens for period",
       x = "Election Group",
       y = "Total") +
  theme_minimal()

# Plot

library(gridExtra)
election_period <- grid.arrange(p_coopt_per_toks, p_repress_per_toks, p_socrevall_per_toks)
# SAVE PLOT

# OPENING OF PARLIAMENTARY YEAR

## REVOLUTIONARY OPPORTUNISM

# Create a new column for Year-Month
df_ft_all_subset <- df_ft_all %>%
  mutate(month_year = format(as.Date(date), "%Y-%m"))

# Aggregate the socrevall values by Year-Month
df_aggregated <- df_ft_all_subset %>%
  group_by(month_year) %>%
  summarise(
    socrevall_aggregate = sum(socrevall),
    total_tokens = sum(n_tokens)
  ) %>%
  ungroup()

df_aggregated$socrevall_per_toks <-  df_aggregated$socrevall_aggregate/df_aggregated$total_tokens

# Filter the data for the years 1917 to 1919
df_filtered <- df_aggregated %>%
  filter(month_year >= "1917-01" & month_year <= "1919-08")

# Plotting the data
socrevall_yearmonth <- ggplot(df_filtered, aes(x = month_year, y = socrevall_per_toks)) +
  geom_line(group = 1) +  # Line plot
  geom_point() +              # Add points to the line
  labs(title = "Revolutionary opportunism",
       x = "Year-Month",
       y = "Total per tokens of month") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# CO-OPTATION

df_ft_all$coopt_aggregate <- df_ft_all$socrevall + df_ft_all$arbejdsløshedsstøtte + df_ft_all$dyrtid + df_ft_all$arbejdsdag + df_ft_all$merindkomstskat

# Create a new column for Year-Month
df_ft_all_subset <- df_ft_all %>%
  mutate(month_year = format(as.Date(date), "%Y-%m"))

# Aggregate the socrevall values by Year-Month
df_aggregated <- df_ft_all_subset %>%
  group_by(month_year) %>%
  summarise(
    coopt_aggregate = sum(coopt_aggregate),
    total_tokens = sum(n_tokens)
  ) %>%
  ungroup()

df_aggregated$coopt_aggregate_per_toks <-  df_aggregated$coopt_aggregate/df_aggregated$total_tokens

# Filter the data for the years 1917 to 1919
df_filtered <- df_aggregated %>%
  filter(month_year >= "1917-01" & month_year <= "1919-08")

# Plotting the data
coopt_yearmonth <- ggplot(df_filtered, aes(x = month_year, y = coopt_aggregate_per_toks)) +
  geom_line(group = 1) +  # Line plot
  geom_point() +              # Add points to the line
  labs(title = "Co-optation",
       x = "Year-Month",
       y = "Total per tokens of month") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# REPRESSION

# Create a new column for Year-Month
df_ft_all_subset <- df_ft_all %>%
  mutate(month_year = format(as.Date(date), "%Y-%m"))

# Aggregate the socrevall values by Year-Month
df_aggregated <- df_ft_all_subset %>%
  group_by(month_year) %>%
  summarise(
    repress = sum(repress),
    total_tokens = sum(n_tokens)
  ) %>%
  ungroup()

df_aggregated$repress_per_toks <-  df_aggregated$repress/df_aggregated$total_tokens

# Filter the data for the years 1917 to 1919
df_filtered <- df_aggregated %>%
  filter(month_year >= "1917-01" & month_year <= "1919-08")

# Plotting the data
repress_yearmonth <- ggplot(df_filtered, aes(x = month_year, y = repress_per_toks)) +
  geom_line(group = 1) +  # Line plot
  geom_point() +              # Add points to the line
  labs(title = "Repression",
       x = "Year-Month",
       y = "Total per tokens of month") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Plot

library(gridExtra)
yearmonth_opening <- grid.arrange(coopt_yearmonth, repress_yearmonth, socrevall_yearmonth)
#SAVE PLOT

# D10

setwd("FOLDER PATH")
load("/df_ft_all_53_72.rda")

# REVOLUTIONARY TERMS
df_ft_all_53_72$word <- str_count(df_ft_all_53_72$speech, "socialis|revolution|kommunis|bolschevi|anarkism|anarkist|syndikalis")

byyear_word <- aggregate(cbind(word)~year, data=df_ft_all_53_72,FUN=sum)

byyear_word <- subset(byyear_word, year < 1973)

#Plot year
p <- ggplot(byyear_word, aes(x = year, y = word)) +
  geom_line() +
  scale_x_continuous(breaks = seq(from = 1900, to = 2017, by = 2)) +
  coord_cartesian(ylim=c(0, 2000))  +
  theme_minimal()
p + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))

# Add annotations with lines in greyscale
p <- p + 
  # Line and text for "Overthrow of Batista"
  geom_segment(aes(x = 1959, xend = 1959, y = 1500, yend = 0), 
               color = "darkgrey", linetype = "dashed") +
  annotate("text", x = 1959, y = 1700, label = "Overthrow of Batista", 
           color = "black", hjust = -0.1, vjust = 1) +
  
  # Line and text for "Bay of Pigs invasion"
  geom_segment(aes(x = 1961, xend = 1961, y = 1500, yend = 0), 
               color = "grey", linetype = "dashed") +
  annotate("text", x = 1961, y = 1500, label = "Bay of Pigs invasion", 
           color = "black", hjust = -0.1, vjust = 1)
# Display the plot
revsocall_cuba <- p + labs(x = "Year", y = "Revolutionary terms") +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
#SAVE PLOT

# CUBA OR CASTRO

df_ft_all_53_72$word <- str_count(df_ft_all_53_72$speech, "Cuba|Castro") #Finder strings, der indeholder word

byyear_word <- aggregate(cbind(word)~year, data=df_ft_all_53_72,FUN=sum)

byyear_word <- subset(byyear_word, year < 1973)

#Plot year
p <- ggplot(byyear_word, aes(x = year, y = word)) +
  geom_line() +
  scale_x_continuous(breaks = seq(from = 1900, to = 2017, by = 2)) +
  theme_minimal()
frequency_cuba <- p + labs(x = "Year", y = "Castro or Cuba") +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
#SAVE PLOT

# MODELS FOR COPYING OUTPUT INTO ARTICLE

## IV 
df_ft_all$y17_19 <- as.numeric(format(df_ft_all$date, '%Y-%m-%d') %between% c('1917-03-08', '1919-08-11'))
df_ft_all_y17_19 <- subset(df_ft_all, format(as.Date(date),"%Y-%m-%d")<'1919-08-12')

## Year cluster
breaks <- seq(as.Date('1910-01-01'), as.Date('1917-03-07'), length.out = 6)
df_ft_all_y17_19 <- df_ft_all_y17_19 %>%
  mutate(year_cluster = cut(date, breaks, labels = FALSE))
df_ft_all_y17_19$year_cluster[df_ft_all_y17_19$date >= as.Date('1917-03-08') &
                                df_ft_all_y17_19$date <= as.Date('1919-08-11')] <- 'Revolution'
df_ft_all_y17_19$year_cluster <- factor(df_ft_all_y17_19$year_cluster)
df_ft_all_y17_19$year_cluster <- relevel(df_ft_all_y17_19$year_cluster, ref = "5")

## Regressions

# Unemployment compensation
glmarbejdsløshedsimple17_19 <- feglm(
  arbejdsløshedsstøtte~y17_19, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

glmarbejdsløshedsimple17_19_inf <- feglm(
  arbejdsløshedsstøtte~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

glmarbejdsløshedsimple17_19_inf_fe <- feglm(
  arbejdsløshedsstøtte~y17_19  + growth + unemp + election + inflation + n_tokens_all + factor(year_cluster)-1, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Working day

glmarbejdsdag17_19 <- feglm(
  arbejdsdag~y17_19, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

glmarbejdsdag17_19_inf <- feglm(
  arbejdsdag~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

glmarbejdsdag17_19_inf_fe <- feglm(
  arbejdsdag~y17_19  + growth + unemp + election + inflation + n_tokens_all +factor(year_cluster)-1, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Price increase compensation

glmdyrtid17_19 <- feglm(
  dyrtid~y17_19, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

glmdyrtid17_19_inf <- feglm(
  dyrtid~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

glmdyrtid17_19_inf_fe <- feglm(
  dyrtid~y17_19  + growth + unemp + election + inflation + n_tokens_all + factor(year_cluster)-1, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Additional taxation
glmmerindkomstskat17_19 <- feglm(
  merindkomstskat~y17_19, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

glmmerindkomstskat17_19_inf <- feglm(
  merindkomstskat~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

glmmerindkomstskat17_19_inf_fe <- feglm(
  merindkomstskat~y17_19  + growth + unemp + election + inflation + n_tokens_all + factor(year_cluster)-1, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Regressions, policies, parties
# Unemployment compensation
glmarbejdsløshedssimple17_19_s_inf <- feglm(
  arbejdsløshedsstøtte ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmarbejdsløshedssimple17_19_k_inf <- feglm(
  arbejdsløshedsstøtte ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmarbejdsløshedssimple17_19_v_inf <- feglm(
  arbejdsløshedsstøtte ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)),
  family = quasipoisson(),
  se = "hetero")

glmarbejdsløshedssimple17_19_r_inf <- feglm(
  arbejdsløshedsstøtte ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

# Working day
glmarbejdsdagsimple17_19_s_inf <- feglm(
  arbejdsdag ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmarbejdsdagsimple17_19_k_inf <- feglm(
  arbejdsdag ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmarbejdsdagsimple17_19_v_inf <- feglm(
  arbejdsdag ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)),
  family = quasipoisson(),
  se = "hetero")

glmarbejdsdagsimple17_19_r_inf <- feglm(
  arbejdsdag ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

# Price increase compensation

glmdyrtidsimple17_19_s_inf <- feglm(
  dyrtid ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmdyrtidsimple17_19_k_inf <- feglm(
  dyrtid ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmdyrtidsimple17_19_v_inf <- feglm(
  dyrtid ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)), 
  family = quasipoisson(),
  se = "hetero")

glmdyrtidsimple17_19_r_inf <- feglm(
  dyrtid ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

# Additional taxation
glmmerindkomstskatsimple17_19_s_inf <- feglm(
  merindkomstskat ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmmerindkomstskatsimple17_19_k_inf <- feglm(
  merindkomstskat ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmmerindkomstskatsimple17_19_v_inf <- feglm(
  merindkomstskat ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)), 
  family = quasipoisson(),
  se = "hetero")

glmmerindkomstskatsimple17_19_r_inf <- feglm(
  merindkomstskat ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

# Revolutionary terms

glmsocrevall17_19 <- feglm(
  socrevall~y17_19, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

glmsocrevall17_19_inf <- feglm(
  socrevall~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

glmsocrevall17_19_inf_fe <- feglm(
  socrevall~y17_19  + growth + unemp + election + inflation + n_tokens_all + factor(year_cluster)-1, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Regressions, revolutionary terms, parties

glmsocrevall17_19_sinf <- feglm(
  socrevall ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmsocrevall17_19_kinf <- feglm(
  socrevall ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmsocrevall17_19_vinf <- feglm(
  socrevall ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)),
  family = quasipoisson(),
  se = "hetero")

glmsocrevall17_19_rinf <- feglm(
  socrevall ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

# Repression

glmrepress17_19 <- feglm(
  repress~y17_19, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

glmrepress17_19_inf <- feglm(
  repress~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

glmrepress17_19_inf_fe <- feglm(
  repress~y17_19  + growth + unemp + election + inflation + n_tokens_all + factor(year_cluster)-1, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Repression, parties

glmrepress17_19_sinf <- feglm(
  repress ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party == 2), 
  family = quasipoisson(),
  se = "hetero")

glmrepress17_19_kinf <- feglm(
  repress ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(3, 7, 8, 16, 101)), 
  family = quasipoisson(),
  se = "hetero")

glmrepress17_19_vinf <- feglm(
  repress ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(4, 13, 14, 15, 103)),
  family = quasipoisson(),
  se = "hetero")

glmrepress17_19_rinf <- feglm(
  repress ~ y17_19 + growth + unemp + election + inflation + n_tokens_all, 
  data = subset(df_ft_all_y17_19, party %in% c(5,102)),
  family = quasipoisson(),
  se = "hetero")

# Revolutionary terms and repression or co-optation

df_ft_all$socrevall_coopt <- ifelse(df_ft_all$socrevall > 0 & (df_ft_all$arbejdsløshedsstøtte > 0 | df_ft_all$dyrtid > 0 | df_ft_all$arbejdsdag > 0 | df_ft_all$merindkomstskat > 0), 1, 0)
df_ft_all$socrevall_repress <- ifelse(df_ft_all$socrevall > 0 & df_ft_all$repress > 0, 1, 0)
df_ft_all$y17_19 <- as.numeric(format(df_ft_all$date, '%Y-%m-%d') %between% c('1917-03-08', '1919-08-11'))
df_ft_all_y17_19 <- subset(df_ft_all, format(as.Date(date),"%Y-%m-%d")<'1919-08-12')
df_ft_all_y17_19$year <- as.numeric(df_ft_all_y17_19$year)
library(fixest)
library(broom)
library(ggplot2)
library(dplyr)

glmsocrevallcoopt17_19_inf <- feglm(
  socrevall_coopt~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

glmsocrevallrepress17_19_inf <- feglm(
  socrevall_repress~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19,
  family = quasipoisson(),
  se = "hetero")

# Robustness to MP change

df_ft_all$y17_19 <- as.numeric(format(df_ft_all$date, '%Y-%m-%d') %between% c('1917-03-08', '1919-08-11'))
df_ft_all_y17_19 <- subset(df_ft_all, format(as.Date(date),"%Y-%m-%d")<'1919-08-12')
df_ft_all_y17_19_1910 <- df_ft_all_y17_19 %>%
  filter(!(y17_19 == 1 & `1910_or_before` != 1))
df_ft_all_y17_19_1910_notempmembers <- df_ft_all_y17_19_1910 %>%
  filter(is.na(not_member_election_10_18) )
df_ft_all_y17_19_1910_notempmembers <- df_ft_all_y17_19_1910_notempmembers %>%
  filter(is.na(not_member_14_18) )
df_ft_all_y17_19_1910_notempmembers <- df_ft_all_y17_19_1910_notempmembers %>%
  filter(is.na(not_member_13_18) )
df_ft_all_y17_19_1910_notempmembers <- df_ft_all_y17_19_1910_notempmembers %>%
  filter(is.na(not_member_10_16) )

glmsocrevall17_19_inf_subset <- feglm(
  socrevall~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_1910_notempmembers,
  family = quasipoisson(),
  se = "hetero")

glmarbejdsløshedsstøtte17_19_inf_subset <- feglm(
  arbejdsløshedsstøtte~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_1910_notempmembers,
  family = quasipoisson(),
  se = "hetero")

glmarbejdsdag17_19_inf_subset <- feglm(
  arbejdsdag~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_1910_notempmembers,
  family = quasipoisson(),
  se = "hetero")

glmdyrtid17_19_inf_subset <- feglm(
  dyrtid~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_1910_notempmembers,
  family = quasipoisson(),
  se = "hetero")

glmmerindkomstskat17_19_inf_subset <- feglm(
  merindkomstskat~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_1910_notempmembers,
  family = quasipoisson(),
  se = "hetero")

glmrepress17_19_inf_subset <- feglm(
  repress~y17_19  + growth + unemp + election + inflation + n_tokens_all, 
  data = df_ft_all_y17_19_1910_notempmembers,
  family = quasipoisson(),
  se = "hetero")

# Tables, aggregate

texreg(
  list(glmarbejdsløshedsimple17_19, glmarbejdsløshedsimple17_19_inf, glmarbejdsdag17_19, glmarbejdsdag17_19_inf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("No controls", "Controls", "No controls", "Controls"),
  caption = "Unemployment support, Working day",
  stars = c(0.05, 0.01, 0.001),   include.loglik = FALSE,   include.pseudors = FALSE, caption.above = TRUE,  
)

texreg(
  list(glmdyrtid17_19, glmdyrtid17_19_inf, glmmerindkomstskat17_19, glmmerindkomstskat17_19_inf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("No controls", "Controls", "No controls", "Controls"),
  caption = "Price increase compensation, Add. tax",
  stars = c(0.05, 0.01, 0.001),   include.loglik = FALSE,   include.pseudors = FALSE, caption.above = TRUE,  
)

# PARTIES, FOR ARTICLE

texreg(
  list(glmarbejdsløshedssimple17_19_s_inf, glmarbejdsløshedssimple17_19_k_inf, glmarbejdsløshedssimple17_19_v_inf, glmarbejdsløshedssimple17_19_r_inf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Unemployment support, parties",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmarbejdsdagsimple17_19_s_inf, glmarbejdsdagsimple17_19_k_inf, glmarbejdsdagsimple17_19_v_inf, glmarbejdsdagsimple17_19_r_inf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Working day, parties",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmdyrtidsimple17_19_s_inf, glmdyrtidsimple17_19_k_inf, glmdyrtidsimple17_19_v_inf, glmdyrtidsimple17_19_r_inf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Price increase compensation, parties",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)

texreg(
  list(glmmerindkomstskatsimple17_19_s_inf, glmmerindkomstskatsimple17_19_k_inf, glmmerindkomstskatsimple17_19_v_inf, glmmerindkomstskatsimple17_19_r_inf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Additional taxation, parties",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)


texreg(
  list(glmrepress17_19, glmrepress17_19_inf, glmrepress17_19_sinf, glmrepress17_19_kinf, glmrepress17_19_vinf, glmrepress17_19_rinf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("No controls", "Controls", "Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Repression",
  stars = c(0.05, 0.01, 0.001), include.loglik = FALSE,   include.pseudors = FALSE, caption.above = TRUE,  
)

texreg(
  list(glmsocrevall17_19, glmsocrevall17_19_inf, glmsocrevall17_19_sinf, glmsocrevall17_19_kinf, glmsocrevall17_19_vinf, glmsocrevall17_19_rinf),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("No controls", "Controls", "Social Democrats", "Conservatives", "Liberals", "Social-Liberals"),
  caption = "Revolutionary terms",
  stars = c(0.05, 0.01, 0.001),   include.loglik = FALSE,   include.pseudors = FALSE, caption.above = TRUE,  
)


# Robustness to MP change

texreg(
  list(glmarbejdsløshedsstøtte17_19_inf_subset, glmarbejdsdag17_19_inf_subset, glmdyrtid17_19_inf_subset, glmmerindkomstskat17_19_inf_subset, glmrepress17_19_inf_subset,  glmsocrevall17_19_inf_subset),
  custom.coef.names = c(
    "(Intercept)",
    "Revolutionary period",
    "Growth",
    "Unemployment",
    "Election",
    "Inflation",
    "Tokens"
  ),
  custom.model.names = c("Unempl. benefits", "Working day", "Price inc. comp.", "Add. taxation", "Repression", "Revolutionary terms"),
  caption = "Signaling, robustness to MP change",
  stars = c(0.05, 0.01, 0.001), 
  include.loglik = FALSE,
  include.pseudors = FALSE, caption.above = TRUE, 
)